c# - How to pass an object using Post Method with help WebRequest class -
how pass object using post
using webrequest
?
my code:
public void createapplication(applicationdata applicationdata, string token, string applicationurl, string xframeurl) { uri uri = new uri(applicationurl); httpwebrequest request = (httpwebrequest)webrequest.create(applicationurl); request.accept = "application/json"; request.referer = xframeurl; request.host = uri.host; request.headers.add("origin", uri.scheme + "://" + uri.host); request.headers.add("authorization", token); request.headers.add("x-requested-with", "xmlhttprequest"); object data = new { culture = applicationdata.culture, endpointid = convert.tostring(applicationdata.endpointid), useragent = applicationdata.applicationname }; request.method = "post"; javascriptserializer jss = new javascriptserializer(); streamwriter writer = new streamwriter(request.getrequeststream()); string content = jss.serialize(applicationdata); writer.write(content); writer.close(); // getting error in following line: bad request using (httpwebresponse response = (httpwebresponse)request.getresponse()) { } }
Comments
Post a Comment