unable to connect the remote server with very simple httpWebRequest class app

馋奶兔 提交于 2019-12-11 09:56:51

问题


I used visual2010 to write a simple app with httpWebRequest class. The very first time of running the app, it'd work but after some successes, it was stuck with warning "unable to connect the remote server". I have read a lot in net but not much clues could done, almost said because the anti virus soft or firewall cause the problem, but when i'd turn off both, it still does not work. I also reinstall visual2010 but the problem still

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;

namespace new_httpWebRequest
{
class Program
{
    static void Main(string[] args)
    {
        string result ="";
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://my-favor.net");
        // line code problem below:
        `HttpWebResponse response = (HttpWebResponse)request.GetResponse();`
        var sr = new StreamReader(response.GetResponseStream() ?? System.IO.Stream.Null, Encoding.UTF8);
        result = sr.ReadToEnd();
        sr.Close();
        Console.Write(result);
        Console.ReadLine();

    }
}

}


回答1:


finally, i find the solution just by adding this line:

request.Proxy = null;

I don't know why it work, just do it by god bless.



来源:https://stackoverflow.com/questions/13283228/unable-to-connect-the-remote-server-with-very-simple-httpwebrequest-class-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!