我遇到了从邮寄请求中获得完整回复的问题。 特别是我的问题是,在Fiddler我得到了完整的回复(下面的回复),在.NET中,我只得到了它的一部分。
我正在使用HttpClient,这就像我的代码看起来像
var validator = require('validator');
validator.isEmpty(string) //returns true or false
在.NET中我得到了这个响应(序列化为json)
var client = new HttpClient();
var response = client.PostAsync(url, content).Result;
但是在Fiddler我得到了这个回应(在RAW视图中)
{"Version":{"Major":1,"Minor":1,"Build":-1,"Revision":-1,"MajorRevision":-1,"MinorRevision":-1},"Content":{"Headers":[{"Key":"Content-Length","Value":["471"]},{"Key":"Expires","Value":["Thu, 19 Nov 1981 08:52:00 GMT"]},{"Key":"Content-Type","Value":["application/json; charset=UTF-8"]}]},"StatusCode":200,"ReasonPhrase":"OK","Headers":[{"Key":"X-Frame-Options","Value":["SAMEORIGIN"]},{"Key":"Pragma","Value":["no-cache"]},{"Key":"Cache-Control","Value":["no-store, must-revalidate, no-cache, post-check=0, pre-check=0"]},{"Key":"Date","Value":["Wed, 19 Apr 2017 22:13:15 GMT"]},{"Key":"Set-Cookie","Value":["SD_FRAMEWORK_SESSION=10ktfgcedl5rq427kvmo0sj7v4; path=/","user=abca7451088; expires=Sat, 20-May-2017 22:13:15 GMT; Max-Age=2678400; httponly","password=d30b0cc02736cf891cfca885ff5245bd; expires=Sat, 20-May-2017 22:13:15 GMT; Max-Age=2678400; httponly"]},{"Key":"Server","Value":["Apache"]},{"Key":"Connection","Value":["close"]}],"RequestMessage":{"Version":{"Major":1,"Minor":1,"Build":-1,"Revision":-1,"MajorRevision":-1,"MinorRevision":-1},"Content":{"Headers":[{"Key":"Content-Type","Value":["application/x-www-form-urlencoded"]},{"Key":"Content-Length","Value":["88"]}]},"Method":{"Method":"POST"},"RequestUri":"http://URL.COM/","Headers":[],"Properties":{}},"IsSuccessStatusCode":true}
那么,我怎样才能在.NET响应中获得特殊部分(" {" special":{" ....")?
答案 0 :(得分:0)
Fiddler显示回复内容。您可以使用HttpResponseMessage
的{{3}}方法从HttpContent
获取内容:
var content = response.Content.ReadAsStringAsync().Result;