c#中的代理服务器测试

时间:2014-06-26 16:32:58

标签: c# proxy

我正在使用代理

发出网络请求
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(inputURL);
WebProxy proxy = new WebProxy(101.1.1.1,80);

wr.Headers.Set(HttpRequestHeader.AcceptLanguage, "en-US");
wr.Timeout = 100000;
wr.Method = "GET";
wr.ContentType = "text/html;charset=UTF-8";

当我查看Fiddler时,我看不到任何代理信息。如何确保代理正确使用?

由于

1 个答案:

答案 0 :(得分:1)

string proxyIP = "61.135.178.114";
int proxyPort = 80;

var req = (HttpWebRequest)HttpWebRequest.Create("http://ip-api.com/json");
req.Proxy = new WebProxy(proxyIP, proxyPort);
var resp =   req.GetResponse();
var json = new StreamReader(resp.GetResponseStream()).ReadToEnd();

var myip = (string)JObject.Parse(json)["query"];

if (myip == proxyIP)
{
    MessageBox.Show("OK...");
}

您需要Json.Net库来运行此代码