I need to make some api calls in C#.
(我需要在C#中进行一些api调用。)
I'm using Web API Client from Microsoft to do that. (我正在使用Microsoft的Web API客户端来执行此操作。)
I success to make some POST requests, but I don't know how to add the field "Body" into my requests. (我成功发出了一些POST请求,但是我不知道如何在请求中添加字段“ Body”。)
Any idea ? (任何的想法 ?)
Here's my code: (这是我的代码:)
static HttpClient client = new HttpClient();
public override void AwakeFromNib()
{
base.AwakeFromNib();
notif_button.Activated += (sender, e) => {
};
tips_button.Activated += (sender, e) =>
{
Tip t1 = new Tip(title_tips.StringValue, pic_tips.StringValue, content_tips.StringValue, "TEST");
client.BaseAddress = new Uri("my_url");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
CreateProductAsync(t1).Wait();
};
}
static async Task<Uri> CreateProductAsync(Tip tips)
{
HttpResponseMessage response = await client.PostAsJsonAsync("api/add_tips", tips);
response.EnsureSuccessStatusCode();
return response.Headers.Location;
}
ask by Baptiste translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…