我正在尝试使用对象将一些数据从 ASP.Net 应用程序发布到 PHP HttpWebRequest
。但是当我尝试使用阅读Request
内容时
Stream myStream = myWebReq.GetRequestStream();
我收到一个错误
“responseStream.Length”引发了“System.NotSupportedException”类型的异常。
Length = 'dataStream.Length' 引发了 'System.NotSupportedException' 类型的异常
Position = 'dataStream.Position' 引发了 'System.NotSupportedException' 类型的异常
这是代码
string strURL = null;
HttpWebRequest myWebReq = default(HttpWebRequest);
HttpWebResponse myWebResp = default(HttpWebResponse);
byte[] byteData = null;
StreamReader sr = default(StreamReader);
strURL = "http://people.com.pk/nppm/hrms_ppm_service.php?dump=1";
myWebReq = (HttpWebRequest)WebRequest.Create(strURL);
myWebReq.ContentType = "application/x-www-form-urlencoded; charset=utf-8";
myWebReq.Method = "POST";
Label1.Text = Newtonsoft.Json.JsonConvert.SerializeObject(batches).ToString();
byteData = UTF8Encoding.UTF8.GetBytes(Label1.Text);
myWebReq.ContentLength = byteData.Length;
myWebReq.KeepAlive = true;
if (myWebReq.Proxy != null)
{
myWebReq.Proxy.Credentials = CredentialCache.DefaultCredentials;
}
Stream myStream = myWebReq.GetRequestStream();
if (byteData.Length > 0)
{
myStream.Write(byteData, 0, byteData.Length);
myStream.Close();
}
myWebResp = (HttpWebResponse)myWebReq.GetResponse();
sr = new StreamReader(myWebResp.GetResponseStream());
string strJSON__2 = sr.ReadToEnd();
Label1.Text = strJSON__2;