Csharp/C#教程:在IIS 6.0上使用.NET WebRequest超时分享


在IIS 6.0上使用.NET WebRequest超时

在我的ASP.NET 2.0 Web服务中,我试图访问Google API来翻译一些文本。 以下代码执行此操作:

string result = ""; // create the web request to the Google Translate REST interface System.Net.WebRequest oRequest = System.Net.WebRequest.Create("https://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=" + System.Web.HttpUtility.UrlEncode("Text to translate") + "&langpair=" + "en" + "%7C" + "fr"); // make the web call System.Net.WebResponse oResponse = oRequest.GetResponse(); // grab the response stream System.IO.StreamReader oReader = new System.IO.StreamReader(oResponse.GetResponseStream()); // put the whole response in a string string sContent = oReader.ReadToEnd(); // parse the string into the litJSON simple object model JsonData oData = JsonMapper.ToObject(sContent); // write out the translated text result = oData["responseData"]["translatedText"].ToString(); 

(JsonData来自DLL LitJson – > https://litjson.sourceforge.net )

只要我在ASP.NET开发服务器上,这就可以正常工作。 但是一旦我将我的Web服务放到我的IIS 6.0服务器上,我的客户端就会出现“操作已超时”的错误。

使用System.Net.WebClient,我得到相同的超时。

IIS上是否有禁止Web请求的设置?

在开发Web服务器中,超时设置为无限。 当您移动到IIS6时,会遵循超时值,然后您的请求需要比默认值更长的时间,然后超时。 在oRequest对象(System.Net.HttpWebRequest对象)上,可以通过设置Timeout属性来更改超时值。 默认超时为100,000毫秒(100秒)。

上述就是C#学习教程:在IIS 6.0上使用.NET WebRequest超时分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

 oRequest.Timeout = 300000; //300,000 milliseconds or 300 seconds or 5 minutes 

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/1015907.html

(0)
上一篇 2021年12月31日
下一篇 2021年12月31日

精彩推荐