🖥

C# でリクエストヘッダを指定しながら HTTP POST 送信

2023/09/01に公開
using System.Text;
using System.Net.Http;
HttpClient client = new HttpClient();

string url = "https://httpbin.org/post";

string parameters = "{" +
    " \"foo1\" : \"bar1\" ," +
    " \"foo2\" : \"bar2\" ," +
    " \"foo3\" : \"bar3\"  }";

var content = new StringContent(parameters, Encoding.UTF8, "application/json");å
client.DefaultRequestHeaders.Add("FOO", "BAR");

HttpResponseMessage response = await client.PostAsync(url, content);
var request = new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Post, url);

var body = await response.Content.ReadAsStringAsync();

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

https://line.me/ti/g2/eEPltQ6Tzh3pYAZV8JXKZqc7PJ6L0rpm573dcQ

Twitter

https://twitter.com/YumaInaura

公開日時

2022-10-27

Discussion