webclient - How to get header value in UploadStringCompletedEventHandler method ASP.NET (Web API Service using HttpClient) -
in windows phone 8 app, create webclient
object , initiate uploadstringasync.
, create webclientlogin.uploadstringcompleted
using uploadstringcompletedeventhandler.
webclient webclientlogin = new webclient(); webclientlogin.headers["content-type"] = "application/json"; webclientlogin.uploadstringcompleted += new uploadstringcompletedeventhandler(webclientuploadstringcompleted); webclientlogin.uploadstringasync(new uri(url + "login"), "post", stockiestdata);
here stockiestdata encoded using encoding.utf8
i response well.
private void webclientuploadstringcompleted(object sender, uploadstringcompletedeventargs e) { var logindetails = jsonconvert.deserializeobject<logresponse>(e.result); }
but need header in above method (webclientuploadstringcompleted). send header follows httpcontext.current.response.appendheader("msg","checked");
response created in webapi
how this?
able header values using sender object in following method.
private void webclientuploadstringcompleted(object sender, uploadstringcompletedeventargs e) { }
we have cast object webclient. following method shows how send in webapi
[httppost] [actionname("login")] public dynamic login(list<student> student, httprequestmessage request) { if (student!= null) { httpcontext.current.response.appendheader("msg", "resived"); }
following code shows how header value windows phone 8
private void webclientuploadstringcompleted(object sender, uploadstringcompletedeventargs e) { webclient web = (webclient)sender; webheadercollection mywebheadercollection = (webheadercollection)web.responseheaders; var v = web.responseheaders["msg"]; }
Comments
Post a Comment