asp.net - Post data must be key value pair? If not how to read raw data in .Net -
i don't think have in pairs, if send plain text below:
httpclient httpclient = new httpclient(); httpclient.postasync("http://hey.com", new stringcontent("simple string, no key value pair."));
then formcollection below doesn't seem offer way read that..
public actionresult index(formcollection collection){ //how string sent collection? }
the formcollection
object key value pair collection. if sending simple string on collection empty unless formatted key\value pair.
this can done in multiple ways.
option 1: send key value pairs, formcollection
read string key mystring
:
httpclient httpclient = new httpclient(); var content = new formurlencodedcontent(new[] { new keyvaluepair<string, string>("mystring", "my string value") }); httpclient.postasync("http://myurl.com", content);
option 2: read contents directly request. reads raw request.inputstream
streamreader
string
public actionresult readinput() { this.request.inputstream.seek(0, system.io.seekorigin.begin); string mystring = ""; using (var reader = new streamreader(this.request.inputstream)) { mystring = reader.readtoend(); } }
there many more options either of these methods should trick