获取内部服务器错误
这里是我的代码我在哪里请求使用HttpWebRequest的URL并从HttpWebResponse获取响应。 但是httpwebresponse对象会引发内部服务器错误!
url="http://www.google.com/"
Uri urlCheck = new Uri(url);
request = (HttpWebRequest)WebRequest.Create(url);
request.Timeout = 5000000;
response = (HttpWebResponse)request.GetResponse(); //Here Getting The Exception..
receiveStream = response.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
strmRead = new StreamReader(receiveStream, encode);
result = strmRead.ReadToEnd();
如果客户端不支持cookie,它看起来像网站崩溃。 因此,您可以通过设置CookieContainer在客户端上启用对Cookie的支持:
using System;
using System.IO;
using System.Net;
class Program
{
static void Main()
{
var url = "http://links.casemakerlegal.com/states/MS/books/Case_Law/results?search[Cite]=77%20So.3d%201094";
var request = (HttpWebRequest)WebRequest.Create(url);
request.CookieContainer = new CookieContainer();
using (var response = request.GetResponse())
using (var stream = response.GetResponseStream())
using (var reader = new StreamReader(stream))
{
string result = reader.ReadToEnd();
Console.WriteLine(result);
}
}
}
“内部服务器错误”的意思就是,您所调用的服务器上出现内部错误。
这可能是服务器上的暂时问题,与您无关,也可能是服务器不喜欢您传递给它的数据。 检查以下内容:
77%20So.3d%201094
是一个有效的搜索值吗? 上一篇: Getting Internal Server Error
下一篇: How to implement UIViewController rotation in response to orientation changes?