WebRequest GetResponse()暂停 [英] WebRequest GetResponse() halts

查看:134
本文介绍了WebRequest GetResponse()暂停的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

我在使用轻量级代理服务器时遇到一些困难:
在Microsoft的WebRequest类的C#示例上工作时,我将代码固定在一条指令下.

代码是:

Hello guys!

I''m having some difficulties working on a light proxy server:
Working on Microsoft''s C# example of WebRequest class, I get my code pinned under an instruction.

The code is:

HttpWebRequest request = (HttpWebRequest) WebRequest.Create("http://www.textfixer.com");

                request.Credentials = CredentialCache.DefaultCredentials;
                request.UserAgent = "Proxy Example";
               
                // get the response and write the status:
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                Console.WriteLine(response.StatusDescription);

                //Get the stream containing content returned by the server
                Stream dataStream = response.GetResponseStream();

                //Open the stream using a StreamReader for easy access
                StreamReader reader = new StreamReader(dataStream);

                //Read the content
                string responseFromServer = reader.ReadToEnd();

                //Display the content
                Console.WriteLine(responseFromServer);



控制台不显示任何内容,浏览器等待响应".如果我停止执行,则程序正在等待
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

我已禁用防火墙,并且以管理员身份在Win7上运行(尽管我怀疑这很重要).

我尝试使用请求的超时属性.设置超时后,它会退出指令,但有一个异常.所以我想没有反应...

有任何见解吗?
非常感谢!

Shpid3r



The console doesn`t display anything, the browser "waits for response". If I stop the execution, the program is waiting on the line
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

I have disabled the firewall and I am running on Win7 as administrator (though I doubt this matters).

I have tried using the Timeout property of the request. After the set timeout, it gets out of the instruction with an exception. So I guess there is no response...

Any insights?
Thanks a lot!

Shpid3r

推荐答案

可能是许多事情之一.上一次尝试此操作时,我需要设置凭据才能通过公司防火墙:
Could be one of many things. The last time I tried this, I needed to set the credentials to get past my corporate firewall:
request.Credentials = CredentialCache.DefaultCredentials; 



MSDN [



There is a code sample on MSDN[^] I found very helpful.

If you are working on a proxy server, you might consider async methods, but I''d get this working first!
Hope this helps.


我在系统中检查了您的代码,工作正常. :)
还与其他args进行了检查,并且也与这些参数一起正常工作

I Checked your code in my System it works Fine. :)
also checked with others args and it works fine with these also

shpid3r写道:
shpid3r wrote:

HttpWebResponse response =(HttpWebResponse)request.GetResponse();

HttpWebResponse response = (HttpWebResponse)request.GetResponse();


我测试了在没有Internet连接时它不会显示任何内容.由于GetResponse(),它等待Internet资源的响应.
请在运行此应用程序时检查您的连接.
有关更多详细信息,请浏览
此链接 [


I test it doesn''t display anything when Internet-connection isn''t available. it waits for Response from Internet Resource because of GetResponse().
please check your Connection while running this application.
and for more details please navigate This link[^]


感谢您的关注!
我认为这是我听起来很傻的时刻,但是...

我正在尝试建立代理.我正在处理的应用程序是将在计算机上运行的进程.它接受端口(在这种情况下为3125)上的传入连接,并应中继请求和响应.

我在我正在使用的同一台计算机上(连接到互联网)运行该程序(开发和删除程序).为了对其进行调试,我将机器的代理设置设置为127.0.0.1:3125,然后在浏览器中键入了网页.

我以为浏览器将通过我的应用程序进行代理,该应用程序将直接在网络上运行(我没有想到我的应用程序将通过Windows的代理设置进行访问).

我更改了测试设置:我使用另一台PC通过代理连接.现在一切顺利.

感谢您测试互联网连接.我觉得很傻:-\
Shpid3r
Thanks for your interest!
I think this is the moment I will sound silly but...

I am trying to build a proxy. The application I am working on is a process that will run on a machine. It accepts incoming connections on a port (3125 in this case) and should relay the request and response.

I run the program (developing and debunging) on the same machine I`m working on (connected to the internet). To debug it, I was setting my machine''s proxy settings to 127.0.0.1:3125 and then tyring a web page in a browser.

I thought the browser would proxy through my application, which would go directly on the web (I didn`t imagine that my application will access itself through Windows'' proxy settings).

I have changed the testing setup: I use a different PC to connect through my proxy. Things go alright now.

Thanks for testing the internet connection. I feel silly :-\
Shpid3r


这篇关于WebRequest GetResponse()暂停的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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