How to simulate http request using WatiN with specific HTTP referrer and query string?

后端 未结 2 1291
孤街浪徒
孤街浪徒 2021-01-17 00:34

When I use WatiN to go to a specific web page, how can I fake the HTTP referrer with a query string (i.e. request is from google search wit

2条回答
  •  醉梦人生
    2021-01-17 01:13

    I needed to do something similar to below:

    // session is a custom version of FiddlerCore.Fiddler
    // details about BeforeRequest -> http://fiddler.wikidot.com/fiddlercore-demo
    session.BeforeRequest += sess =>
        sess.oRequest
            .headers
            .Add(
                "Referer",
                "http://www.i-am-middle-man.com/q=black"
            );
    
    session.BeforeResponse += sess =>
            {
                //sess.oResponse.headers.HTTPResponseCode
                //sess.oResponse.headers["Host"]
            };
    
    var handler = WatiNHandler(BrowserTypes.IE);
    handler.GoTo("http://www.my-url.com/");
    

提交回复
热议问题