【发布时间】:2017-09-25 02:16:05
【问题描述】:
HttpWebRequest 有一些问题。我正在尝试管理具有 WebService 的服务器和具有 CF 2.0 客户端的 Windows CE 6.0 之间的连接,而我的实际目的是检索 Windows CE 机器的外部 IP。我尝试使用HttpWebResponse,但它在通话过程中卡住了。
现在我会更清楚,这是我在 WinCE 机器上运行以获取 IP 的代码:
private string GetIPAddressRemote()
{
Uri validUri = new Uri("http://icanhazip.com");
try
{
string externalIP = "";
HttpWebRequest httpRequest = (HttpWebRequest)HttpWebRequest.Create(validUri);
httpRequest.Credentials = CredentialCache.DefaultCredentials;
httpRequest.Timeout = 10000; // Just to haven't an endless wait
using (HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse())
/* HERE WE ARE
* In this point my program stop working...
* well actually it doesn't throw any exception and doesn't crash at all
* For that reason I've setted the timeout property because in this part
* it starts to wait for a response that doesn't come
*/
{
using (Stream stream = httpResponse.GetResponseStream())
{
// retrieve the return string and
// save it in the externalIP variable
}
}
return externalIP;
}
catch(Exception ex)
{
return ex.Message;
}
}
那么,我的问题是什么?我不知道为什么它在httpRequest.GetResponse() 通话期间卡住了,知道吗?
我不得不说我在代理下,所以我想出了代理可能会阻止一些请求的想法,是吗?
【问题讨论】:
标签: c# httpwebrequest compact-framework windows-ce httpwebresponse