HttpWebResponse远程服务器返回错误: (500) 内部服务器错误 的解决办法
2010-02-26 18:09
841 查看
例子:
myHttpWebRequest.Method = "POST";
Console.WriteLine ("/nPlease enter the data to be posted to the (http://www.contoso.com/codesnippets/next.asp) Uri :");
// Create a new string object to POST data to the Url.
string inputData = Console.ReadLine ();
string postData = "firstone=" + inputData;
ASCIIEncoding encoding = new ASCIIEncoding ();
byte[] byte1 = encoding.GetBytes (postData);
// Set the content type of the data being posted.
myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";
// Set the content length of the string being posted.
myHttpWebRequest.ContentLength = byte1.Length;
Stream newStream = myHttpWebRequest.GetRequestStream ();
newStream.Write (byte1, 0, byte1.Length);
Console.WriteLine ("The value of 'ContentLength' property after sending the data is {0}", myHttpWebRequest.ContentLength);
// Close the Stream object.
newStream.Close ();
一般都是执行到 Stream newStream = myHttpWebRequest.GetRequestStream (); 的时候会抛出500 服务器错误,而且有时候会,有时候不会,本人试了很久才找到解决办法,
原来是 myHttpWebRequest.ContentType = "application/x-www-form-urlencoded"; 这个的原因,改成
myHttpWebRequest.ContentType = "text/html"; 问题就解决了!汗!
myHttpWebRequest.Method = "POST";
Console.WriteLine ("/nPlease enter the data to be posted to the (http://www.contoso.com/codesnippets/next.asp) Uri :");
// Create a new string object to POST data to the Url.
string inputData = Console.ReadLine ();
string postData = "firstone=" + inputData;
ASCIIEncoding encoding = new ASCIIEncoding ();
byte[] byte1 = encoding.GetBytes (postData);
// Set the content type of the data being posted.
myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";
// Set the content length of the string being posted.
myHttpWebRequest.ContentLength = byte1.Length;
Stream newStream = myHttpWebRequest.GetRequestStream ();
newStream.Write (byte1, 0, byte1.Length);
Console.WriteLine ("The value of 'ContentLength' property after sending the data is {0}", myHttpWebRequest.ContentLength);
// Close the Stream object.
newStream.Close ();
一般都是执行到 Stream newStream = myHttpWebRequest.GetRequestStream (); 的时候会抛出500 服务器错误,而且有时候会,有时候不会,本人试了很久才找到解决办法,
原来是 myHttpWebRequest.ContentType = "application/x-www-form-urlencoded"; 这个的原因,改成
myHttpWebRequest.ContentType = "text/html"; 问题就解决了!汗!
相关文章推荐
- HttpWebResponse远程服务器返回错误: (500) 内部服务器错误。
- HttpWebResponse远程服务器返回错误: (500) 内部服务器错误。
- HttpWebResponse远程服务器返回错误: (500) 内部服务器错误
- HttpWebResponse远程服务器返回错误: (500) 内部服务器错误。
- HttpWebResponse远程服务器返回错误: (500) 内部服务器错误。
- 远程服务器返回错误: (500) 内部服务器错误解决办法
- 远程服务器返回错误: (500) 内部服务器错误解决办法
- 远程服务器返回错误: (500) 内部服务器错误解决办法
- 通过httpwebrequest实现http的post和get方法莫名出现500内部服务器错误的解决办法
- C# 模拟post数据提交时 出现如下错误: System.Net.WebException: 远程服务器返回错误: (417) Expectation Failed 的解决办法
- http 500内部服务器错误的解决办法(windows xp + IIS
- [转]C# post数据时 出现如下错误: System.Net.WebException: 远程服务器返回错误: (417) Expectation Failed 的解决办法
- IIS 5的http 500内部服务器错误的一般解决办法
- 【IIS问题】解决HTTP500内部服务器错误办法之归纳
- C# post数据时 出现如下错误: System.Net.WebException: 远程服务器返回错误: (417) Expectation Failed 的解决办法
- 【IIS问题】解决HTTP500内部服务器错误办法之归纳
- HttpWebResponse 远程服务器返回错误: (407) 需要代理身份验证。
- 【IIS问题】解决HTTP500内部服务器错误办法之归纳 推荐
- HTTP 500 - 内部服务器错误 解决办法
- http 500内部服务器错误的解决办法(windows xp + IIS5.0)