Closed NoneDay closed 8 years ago
我的做法是: public static class RequestUtility { private static WebProxy _webproxy = null; public static void SetHttpProxy(string host, string port, string username, string password) { ICredentials cred; cred = new NetworkCredential(username, password); if (!string.IsNullOrEmpty(host)) { _webproxy = new WebProxy(host + ":" + port ?? "80", true, null, cred); } }
#region 同步方法
/// <summary>
/// 使用Get方法获取字符串结果(没有加入Cookie)
/// </summary>
/// <param name="url"></param>
/// <returns></returns>
public static string HttpGet(string url, Encoding encoding = null)
{
WebClient wc = new WebClient();
wc.Proxy = _webproxy;
wc.Encoding = encoding ?? Encoding.UTF8;
//用户调用SetHttpProxy设置代理或取消代理。
@lzmch @jiehanlin 非常感谢两位的建议,Senparc.Weixin.dll v4.5.7中已经加入了web代理的功能。欢迎多提意见,感谢!
我的微信服务器是在内网上,如果要访问外部腾讯的网址,必须要加代理。我现在是手工修改程序然后编译的。希望能在RequestUtility 的正式版本中能直接加上类似代码。以后我就更新sdk就不用手工改了。不知道能不能响应我的需求。 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); String proxy_host = System.Configuration.ConfigurationManager.AppSettings["PROXY_HOST"]; String proxy_port = System.Configuration.ConfigurationManager.AppSettings["PROXY_PORT"];