c# - HttpWebReqest headers not sent depending on order when RequestStream was populated -
i'm writing .net 2 code , forced using it's tools. i'm,trying send put
, attach headers (i.e. user-agent). code:
void main() { var req = (httpwebrequest)webrequest.create("http://requestb.in/xan9icxa"); req.method = "put"; req.contenttype = "application/json"; // fillrequestbody("{'c':'d'}", req); req.useragent = "linqpad/4"; fillrequestbody("{'a':'b'}", req); var resp = (httpwebresponse) req.getresponse(); //resp.dump(); } private static void fillrequestbody(string contentasstring, webrequest request) { var databytes = encoding.utf8.getbytes(contentasstring); request.contentlength = databytes.length; using (var requeststream = request.getrequeststream()) requeststream.write(databytes, 0, databytes.length); }
that runs fine , i'm getting headers expected:
user-agent: linqpad/4 content-length: 9 connection: close content-type: application/json
but when run fillrequestbody("{'c':'d'}", req);
instead of fillrequestbody("{'a':'b'}", req);
(which tried , spent time trying figure out why) - user agent not sent:
content-type: application/json connection: close content-length: 9
the difference order of call when i'm filling request stream data: before setting user-agent header after it.
my question why happening - there documentation says filling body of request has last thing before sending http message?
Comments
Post a Comment