c# - My HttpWebRequest "POST" failed since I upgrade to v5.2.2 of Microsoft.NETCore.UniversalWindowsPlatform (before I used v5.1.0) -
i notice between v5.2 , 5.1 of microsoft.netcore.universalwindowsplatform
i have app in v5.1 , "post" opperation whith httpwebrequest , parameter in body encode in utf8. (to simulate login on website) if upgrade v5.2, post stop working ! restore v5.1 , work again ! have got idea ?
mycode
httpwebrequest request = (httpwebrequest)webrequest.create(urlrest.absoluteuri); request.cookiecontainer = new cookiecontainer(); asciiencoding encoding = new asciiencoding(); //encoding.utf8.getbytes(poststring); byte[] postdata = encoding.utf8.getbytes(allparaminbody); //allparamin_body contain : user=myuser&password=mypassword request.contenttype = "post"; request.headers["user-agent"] = "apache-httpclient/4.1.1 (java 1.5)"; stream newstream = await request.getrequeststreamasync(); newstream.write(postdata, 0, postdata.length); newstream.dispose(); response = (httpwebresponse)await request.getresponseasync();
thanks
httpwebrequest not recommended use in uwp apps. ref demystifying httpclient apis in universal windows platform:
as universal windows platform (uwp) app developer, if trying communicate on http web service or server endpoint, have multiple api choices. 2 of used , recommended apis implementing http client role in managed uwp app system.net.http.httpclient , windows.web.http.httpclient. these apis should preferred on older, discouraged apis such webclient , httpwebrequest (although small subset of httpwebrequest available in uwp backward compatibility).
also, can refer my previous answer here. according requirement, can choose either system.net.http.httpclient
or windows.web.http.httpclient
. , here official httpclient sample on github uses windows.web.http
namespace.
besides, httpwebrequest.contenttype
should mime type x-www-form-urlencoded
or text/html
. post
ia not valid value. should value of httpwebrequest.method
property.
Comments
Post a Comment