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;