所以我在学校的程序中使用了一些 POST 请求,它工作正常。我今天回到学校却发现我的代码不再工作了。这是它返回的错误:
System.Configuration.ConfigurationErrorsException: Error creating the Web Proxy specified in the 'system.net/defaultProxy' configuration section. ---> System.Net.Sockets.SocketException: An invalid argument was supplied
at System.Net.NetworkAddressChangePolled..ctor()
at System.Net.AutoWebProxyScriptEngine.AutoDetector.Initialize()
at System.Net.AutoWebProxyScriptEngine..ctor(WebProxy proxy, Boolean useRegistry)
at System.Net.WebProxy.UnsafeUpdateFromRegistry()
at System.Net.Configuration.DefaultProxySectionInternal..ctor(DefaultProxySection section)
at System.Net.Configuration.DefaultProxySectionInternal.GetSection()
--- End of inner exception stack trace ---
at System.Net.Configuration.DefaultProxySectionInternal.GetSection()
at System.Net.WebRequest.get_InternalDefaultWebProxy()
at System.Net.HttpWebRequest..ctor(Uri uri, ServicePoint servicePoint)
at System.Net.HttpRequestCreator.Create(Uri Uri)
at System.Net.WebRequest.Create(Uri requestUri, Boolean useUriBase)
at FileFriend.Net.POST(String url, String dataP)
这是我的邮政编码:
public static String POST(string url, string dataP)
{
string responseString;
try
{
HttpWebRequest httpWReq = (HttpWebRequest)WebRequest.Create(@url) as HttpWebRequest;
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = dataP;
byte[] data = encoding.GetBytes(postData);
httpWReq.Method = "POST";
httpWReq.ContentType = "application/x-www-form-urlencoded";
httpWReq.ContentLength = data.Length;
using (Stream stream = httpWReq.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
HttpWebResponse response = (HttpWebResponse)httpWReq.GetResponse();
responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
}
catch (Exception e)
{
Clipboard.SetText(e.ToString());
return e.ToString();
}
return responseString;
}
无法完全弄清楚发生了什么变化。
编辑:
我的 App.config 文件:
<?xml version="1.0"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>