c# - Request parameter in Windows Mobile for REST API's -
i have 1 windows handheld device application on .net framework 3.5 has requirement of accessing rest api. rest api gives me json output going process later. have following code that:-
httpwebrequest webrequest; string result = string.empty; try { webrequest = (httpwebrequest)webrequest.create(url); webrequest.method = "post"; webrequest.keepalive = false; webrequest.contenttype = "application/x-www-form-urlencoded"; using (webresponse response = webrequest.getresponse()) { using (streamreader streamreader = new streamreader(response.getresponsestream())) { result = streamreader.readtoend(); } } } catch (exception ex) { result = ex.message; }
the url variable holding url api query parameters in it. example "http://www.something.com/login?id=test&pwd=test".
now problem dont want use query string parameters rather want use request parameters because above approach not work every time perfectly. times "unauthorized" error. , have 1 tokenid need send everytime calling api , token id in base64 format.
can please me how can use request parameter feature send parameter values?
use headers
property of request object.
webrequest.headers.add("id", "test"); webrequest.headers.add("pwd", "test"); webrequest.headers.add("token", mytoken);
Comments
Post a Comment