request.GetResponse()出错 [英] Error in request.GetResponse()
本文介绍了request.GetResponse()出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码
Here is my code
string parameters = @"OrderId,OrderedDate,OrderType,ProductId,SubscriptionPeriod,SubscriptionPrice,SubscriptionVolumeCount,SubscriptionScheduleId,UserId" +
Environment.NewLine + "1,2013-08-07 19:41:28,1,1300002727,1,800,1,961193,1";
// string parameters = strArray[1];
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.ContentType = "application/x-www-form-urlencoded";
request.Method = "POST";
request.KeepAlive = false;
byte[] bytes = Encoding.ASCII.GetBytes(parameters);
request.ContentLength = bytes.Length;
using (Stream os = request.GetRequestStream()) // this line gets the error
{
os.Write(bytes, 0, bytes.Length);
os.Close();
using (WebResponse response = request.GetResponse())
{
if (response == null)
{
Console.WriteLine("Response is null");
}
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
string s=reader.ReadToEnd().Trim();
ErrorLog.WriteLog("FujiApiPost", "FujiApiPostfn", "result:" + s, string.Empty, string.Empty);
}
}
}
错误:-Length ='os。长度'抛出类型'System.NotSupportedException'的异常'
Error:-Length = 'os.Length' threw an exception of type 'System.NotSupportedException'
推荐答案
参考 - HttpWebRequest.GetRequestStream方法 [ ^ ]。
Refer - HttpWebRequest.GetRequestStream Method[^].
Quote:
请求缓存验证器指示可以从缓存提供该请求的响应;但是,写入数据的请求不得使用缓存。如果您使用的是错误实现的自定义缓存验证程序,则会发生此异常。
|