0
我想从WEB API调用中获取结果,但无法找到检索JSON结果的方法。 这里是一个调用Web API代码:如何在调用WEB API后获取JSON响应字符串
string baseAddress = "http://server001/";
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(baseAddress + "API/Import");
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
Stream reqStream = req.GetRequestStream();
string fileContents = xml;
byte[] fileToSend = Encoding.UTF8.GetBytes(fileContents);
reqStream.Write(fileToSend, 0, fileToSend.Length);
reqStream.Close();
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
Console.WriteLine("HTTP/{0} {1} {2}", resp.ProtocolVersion, (int)resp.StatusCode, resp.StatusDescription);
//string jsonResult = resp. <=== here
提琴手调用Web API后的结果:
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/8.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Fri, 17 Jan 2014 01:10:00 GMT
Content-Length: 57
{"isError":false,"Msg":"Server data added successfully."}
谢谢!
对!谢谢! – Max