我知道C#但是UWP的新手......我注意到UWP中不存在一些HttpWebRequest
定义。如何在UWP应用程序中使用ContentLength
,GetRequestStream
和GetResponse
?谢谢。如果需要,这是我的代码:
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(SelectedItem + url);
webRequest.Headers.Add("SOAPACTION", SOAPACTION);
webRequest.Method = "POST";
webRequest.ContinueTimeout = 2000;
webRequest.ContentType = "text/xml";
string postData = xmlData;
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
webRequest.ContentLength = byteArray.Length;
Stream dataStream = webRequest.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Dispose();
WebResponse response = webRequest.GetResponse();
dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
reader.Dispose();
response.Dispose();
return responseFromServer;