HttpClient PostAsJsonAsync请求 [英] HttpClient PostAsJsonAsync request

查看:91
本文介绍了HttpClient PostAsJsonAsync请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将对象作为httprequest的一部分发送.这些值是从Specflow表中填充的.

I am trying to send an Object as part of httprequest. The values are populated from Specflow table.

public class Request
{
    public Dictionary<string, dynamic> RequestParameters = 
                                                    new Dictionary<string, dynamic>();
    public void setRequestParameters(Table table)
    {

        foreach (var row in table.Rows)
        {
            try
            {
                RequestParameters.Add(row[0], row[1]);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }
}

Request request = new Request();
request.setRequestParameters(table);
var result = client.PostAsJsonAsync<Request>(_address.ToString(), request).Result;

该值已发送,但是我不希望memberName(RequestParameters)包含这些值.有没有办法忽略它?

The value is sent however I don't want the memberName(RequestParameters) enclosing the values. Is there a way to ignore it?

{
   "RequestParameters":{  
      "InitialCashAmount":"10000.00",
      "TransferAmount":"5000.00",
      "PersonalRegularContribution":"100.00"
   }
}

推荐答案

使用 request.RequestParameters

var result = client.PostAsJsonAsync<Dictionary<string, dynamic>>(_address.ToString(), request.RequestParameters).Result;

这篇关于HttpClient PostAsJsonAsync请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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