asp.net - How to handle and get the body from POST using .NET C#? -
so, know how form data out using request.form["abc"] how go getting body out?
i've used snippet in below link:
https://gist.github.com/leggetter/769688
but, i'm not sure pass in response.
in php this: file_get_contents('php://input'); , it's simple that.
notes: content type of post application/json , body contains json string.
thanks in advance.
if understood question correctly, here's when posting resource expect json response:
httpwebrequest httpwebrequest = (httpwebrequest)webrequest.create("http://foo.com/bar/"); httpwebrequest.method = webrequestmethods.http.post; httpwebrequest.accept = "application/json"; httpwebresponse response = (httpwebresponse)httpwebrequest.getresponse(); stream receivestream = response.getresponsestream(); streamreader readstream = new streamreader (receivestream, encoding.utf8); //store json in variable later use string json = readstream.readtoend(); //make sure close response.close(); readstream.close(); of course, approach synchronous; but, depending on requirements, might fine.
since question didn't specify whether need know how parse json itself, i've left out example of json parsing.
Comments
Post a Comment