Web请求突然无法正常工作

时间:2013-07-03 21:15:20

标签: c# xamarin.ios xamarin

我的应用就像这样打电话给我的api:

Debug.WriteLine ("Making an API request: " + action);
var request = HttpWebRequest.Create("http://domain.com/api/"+ action");
request.ContentType = "application/json";
request.Method = "GET";
string content = "d";

using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
    using (StreamReader reader = new StreamReader(response.GetResponseStream()))
    {
        content = reader.ReadToEnd();
    }
}

return content;

这已经好几个月了。突然有一天我的应用程序不再工作了。调试我发现请求超时或抛出错误:

 (System.Net.WebException) Error getting response stream (ReadDone1): ReceiveFailure

这个错误是什么意思?它为什么突然开始?自应用发布以来,此代码尚未更改。键入浏览器时,该请求可以正常工作。

3 个答案:

答案 0 :(得分:3)

www.添加到修复此问题的所有网址。

答案 1 :(得分:0)

此异常是由连接超时引起的。可能的原因是http://domain.com/api/“+操作提供的服务不再可用,暂时无法使用,或者您的互联网连接已关闭。

答案 2 :(得分:0)

尝试使用HTTPWebRequest的代理设置,例如:

request.Proxy = WebRequest.DefaultWebProxy;
// request.Proxy = WebRequest.GetSystemWebProxy();
request.Proxy.Credentials = CredentialCache.DefaultNetworkCredentials;

我有类似的异常(但是在下载图片时,没有调用远程方法)并且它有所帮助。

相关问题