0

So I am using some POST requests in my program at school and it was working fine. I came back to school today only to find my code doesn't work anymore. Here is the error it returns:

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)

Here is my post code:

    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;
    }

Can't quite figure out what has changed.

EDIT:

My App.config file:

<?xml version="1.0"?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
    </startup>
</configuration>
3
  • 1
    There's a problem with your configuration file. Take a look at your app.config/web.config. It's probably in the system.net section. May 30, 2013 at 23:53
  • I added the App.config file contents to OP. I don't see anything wrong though. May 30, 2013 at 23:58
  • yeah that looks fine to me as well... It's complaining about the default proxy, which can be set in your app.config, however it could also be set in your machine config... Might be worth a look. May 31, 2013 at 0:31

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.