c# - ContentLength in Not available for HttpWebRequest in Windows Phone 8.1 Universal Apps -


i used below code in content length not coming httpwebrequest. alternative that.

byte[]  buffer = ...request data bytes var webreq = (httpwebrequest) webrequest.create("http://127.0.0.1/target");  webreq.method = "required method"; webreq.contenttype = "required content type"; webreq.contentlength = buffer.length;  var reqstream = webreq.getrequests`enter code here`tream(); reqstream.write(buffer, 0, buffer.length); reqstream.close();  var webresp = (httpwebresponse) webreq.getresponse(); 

there changes in winrt api, can't find contentlength property in httpwebrequest class. instead, need choose use ihttpcontent.headers .

you can check following code quick reference:

windows.web.http.httpclient client = new windows.web.http.httpclient();             var body = string.format("body string");             windows.web.http.httpstringcontent thecontent = new windows.web.http.httpstringcontent(body, windows.storage.streams.unicodeencoding.utf8, "application/x-www-form-urlencoded");             thecontent.headers["content-length"] = "length";             windows.web.http.httpresponsemessage aresponse = await client.postasync(new uri("http://127.0.0.1/target"), thecontent); 

Comments