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

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -