网络API - 调试显示混乱的信息 [英] Web API - debugging shows confusing information

查看:145
本文介绍了网络API - 调试显示混乱的信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经得到帮助<一个href=\"http://stackoverflow.com/questions/35272514/issue-with-restful-webservice-jsonsql-stored-procedure-project\">here和<一个href=\"http://stackoverflow.com/questions/35293864/how-to-loop-through-list-of-complex-type-objects-and-pass-to-a-method-calling-sq\">here我的Web API,但现在我想我已经到达大峡谷的边缘......好在我执行我的老板被推迟,但判决还没有改判。因此,任何建议AP preciated全心全意以来,特别是在东西我新手的地位仍未改变。

I've already got help here and here with my Web API, but now I think I've arrived to the edge of a Grand Canyon... Fortunately my execution by my boss was postponed, but sentence was not yet commuted. So any suggestions appreciated wholeheartedly, especially since my newbie status in the stuff hasn't yet changed.

因此​​,code与第二个链接的问题显示(可张贴在这里,但我认为这是多余的)。我已经纠正了与SQL链接错误,所以现在尝试调用程序时不会崩溃,设置调试ENVIRO,并开始测试。

So, the code is as shown in second linked question (can post it here, but I think it would be redundant). I've corrected errors with SQL link, so it now doesn't crash when trying to call procedure, set up debug enviro and started testing.

我(在有效载荷与JSON)使用ARC推广Chrome浏览器在调试时,我有一个错误信息发送POST请求:的

I'm sending a POST request (with JSON in payload) using ARC extension in Chrome while debugging and I have an error message:

不过,使用从答案和意见建议,不断变化的code后:

However, after changing code using suggestions from answers and comments to this:

namespace NA.Controllers
{
    public class NotesController : ApiController
    {

        [Route("AddNote")]
        [HttpPost]
        public HttpResponseMessage PostNote()
        {
            HttpResponseMessage response = new HttpResponseMessage();
            StreamReader stream = new StreamReader(HttpContext.Current.Request.InputStream);
            string jsonData = stream.ReadToEnd();
            System.IO.File.WriteAllText(@"C:\temp\BLZ_content.txt", jsonData);
            return response;
        }

    }
}

我获得了成功,正确的响应和JSON被保存到一个文件。所以一般API工作正常。这,反过来,意味着我的code为反序列化JSON(或只是从身体捕获它)不是。

I get a success, correct response and json is being saved to a file. So API in general works fine. This, in turn, means that my code for deserialize json (or just capturing it from body) is not.

推荐答案

您无法读取从响应对象,你刚刚创建的输入数据。你必须从这样的请求阅读:

You can not read incoming data from the response object you just created. You have to read it from the Request like this:

string jsonData = new StreamReader(Request.InputStream).ReadToEnd();

然后就可以将其记录到文件,看看是否你得到你期待得到什么。如果这样做,则可以手动反序列化jsonData列出这样的:

Then you can log it to the file to see if you are getting what you are expecting to get. If you do, you can then deserialize manually jsonData to List like this:

List<Note> response = JsonConvert.DeserializeObject<List<Note>>(jsonData);

这篇关于网络API - 调试显示混乱的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆