无法使用非常简单的httpWebRequest类应用程序连接远程服务器 [英] unable to connect the remote server with very simple httpWebRequest class app

查看:230
本文介绍了无法使用非常简单的httpWebRequest类应用程序连接远程服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用visual2010用httpWebRequest类编写了一个简单的应用程序。第一次运行该应用程序时,它可以运行,但是在成功运行之后,它一直停留在警告
无法连接远程服务器上。
我已阅读网上说很多,但没有太多线索可做,几乎说是因为防病毒软件或防火墙引起了问题,但是当我同时关闭两者时,它仍然不起作用。我还重新安装了visual2010,但问题仍然是

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();

    }
}

}

推荐答案

最后,我只需添加以下行即可找到解决方案:

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

request.Proxy = null;

request.Proxy = null;

我不知道它为什么起作用,请上帝保佑。

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

这篇关于无法使用非常简单的httpWebRequest类应用程序连接远程服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆