如何在UWP应用程序中使用Contentlength,GetResponse或GetRequestStream(C#)

时间:2017-08-14 03:52:31

标签: c# uwp httpwebrequest

我知道C#但是UWP的新手......我注意到UWP中不存在一些HttpWebRequest定义。如何在UWP应用程序中使用ContentLengthGetRequestStreamGetResponse?谢谢。如果需要,这是我的代码:

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;

0 个答案:

没有答案