How can we perform a jQuery $.ajax POST with .net code -


how run following code webclient (or equivalent) in .net?

function timeout_trigger() {                 $.ajax({                     type: "post",                     url: "timer.asmx/fetchtimerinfo",                     data: "{'query':'2342600006524'}",                     contenttype: "application/json; charset=utf-8",                     datatype: "json",                     success: function(msg) {                       console.log(msg.d);                     }                 });             } 

attempted in vb.net , got 500 error:

    dim w = new net.webclient     dim d = new namevaluecollection      d.add("query", "2342600006524")      dim r = w.uploadvalues("http://usage.swiftng.com/timer.asmx/fetchtimerinfo", d) 

i able expected results using fiddler composer:

post http://usage.swiftng.com/timer.asmx/fetchtimerinfo http/1.1 host: usage.swiftng.com connection: keep-alive content-length: 25 pragma: no-cache cache-control: no-cache accept: application/json, text/javascript, */* origin: http://usage.swiftng.com x-requested-with: xmlhttprequest user-agent: mozilla/5.0 (windows nt 6.3; win64; x64) applewebkit/537.36 (khtml, gecko) chrome/44.0.2376.0 safari/537.36 content-type: application/json; charset=utf-8 referer: http://usage.swiftng.com/timer.aspx?2342600006524 accept-encoding: gzip, deflate accept-language: en-gb,en;q=0.8,en-us;q=0.6  {'query':'2342600006524'} 

please advise, wrong? thanks!

you can use webrequest class post data. check out guidelines send post values , response using httpwebrequest

here working example:

dim jsondatabytes = encoding.utf8.getbytes("{'query':'2342600006524'}")         dim req webrequest = webrequest.create("http://usage.swiftng.com/timer.asmx/fetchtimerinfo")         req.contenttype = "application/json"         req.method = "post"         req.contentlength = jsondatabytes.length           dim stream = req.getrequeststream()         stream.write(jsondatabytes, 0, jsondatabytes.length)         stream.close()          dim response = req.getresponse().getresponsestream()          dim reader new streamreader(response)         dim res = reader.readtoend()         reader.close()         response.close()