api - Send Web request working with rest client app, but not working with c# -


i sending post request api c# webrequest , httpclient error message api says posted invalid data in header , point when send same data chrome extension advanced rest client works fine , compared both request there nothing different have attached both request , code , can figure out problem ,

this request rest client app:

enter image description here

and here request c#

enter image description here

and here c# code

 string item = "<?xml version=\"1.0\" encoding=\"utf - 8\"?>" +   "<request>" +   "<username>admin</username>" +   "<password>" + password + "</password>" +   "<password_type>4</password_type>" +   "</request> "; var request = (httpwebrequest)webrequest.create("http://192.168.8.1/api/user/login"); request.method = "post"; request.headers["_requestverificationtoken"]= token; request.headers["cookie"] = sess; byte[] bytes = encoding.utf8.getbytes(item); request.contenttype = "application/xml;charset=utf-8"; request.contentlength = bytes.length; stream streamreq = request.getrequeststream(); streamreq.write(bytes, 0, bytes.length); streamreq.close(); using (httpwebresponse response = (httpwebresponse)request.getresponse()) using (streamreader reader = new streamreader(response.getresponsestream())) {     var result = reader.readtoend(); } 

it looks __requestverificationtoken contains 2 underscores in left picture, try this:

request.headers["__requestverificationtoken"]= token; 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -