我想在c#中使用WebClient连接到互联网 连接成功但在更改app.config中的代理配置后停止工作
这是配置
<system.net>
<defaultProxy enabled="true">
<proxy proxyaddress="http://192.168.10.33"/>
</defaultProxy>
</system.net>
以及我如何连接互联网
public async Task<T> PostAsync<T>(string uri, NameValueCollection pairs)
{
byte[] response = null;
using (WebClient client = new WebClient())
{
try
{
response = await Task<byte[]>.Factory.StartNew(() =>
{
return client.UploadValues(uri, pairs);
});
}
catch (WebException e)
{
Trace.WriteLine(e);
response = null;
}
}
if (response != null)
{
string resultAsString = System.Text.Encoding.UTF8.GetString(response);
T result = JsonConvert.DeserializeObject<T>(resultAsString);
return result;
}
return default(T);
}