Getting Internal Server Error
Here Is My Code Where I'm Making Request A URL Using HttpWebRequest And Getting Response From HttpWebResponse. But httpwebresponse object throws an exception that is Internal Server Error!
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();
It looks like the site is crashing if the client doesn't support cookies. So you could enable support for cookies on the client by setting a CookieContainer:
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);
}
}
}
"Internal Server Error" means exactly that, an internal error on the server you are calling.
This might be a temporary problem on the server that is nothing to do with you, or it might be that the server doesn't like the data you are passing to it. Check the following:
77%20So.3d%201094
a valid search value? 上一篇: (500内部服务器错误
下一篇: 获取内部服务器错误