POST JSON with Flurl

半世苍凉 提交于 2019-12-06 05:19:25

I think 2 problems have been identified here.

  1. You're using PostUrlEncodedAsync, which is going to send the data in URL-encoded format, like this: name=device:domain\\login&pwd=123456. If you want the data serialized to JSON, use PostJsonAsync instead.

  2. You're only including the nested attributes object of the JSON and not the entire object.

In short, you're going to want something like this:

var result = await "https://IP/api/aaaLogin.json".PostJsonAsync(new
{
    aaaUser = new
    {
        attributes = new
        {
            name = "device:domain\\login",
            pwd = "123456"
        }
    }
});

Once you get this far, you're going to need to know how to process the results. If the response is JSON formatted, you'll likely want to append .ReceiveJson() or .ReceiveJson<T>() to the above call in order to have a more friendly object to work with. Please refer to the documentation.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!