2
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

RestSharpでBodyに直接Jsonを記述する方法

Posted at

RestSharpについて

こちらをどうぞ

やりたいこと

  • RestSharpでパラメータではなくBodyに直接記入でJson文字列を送信したい。

やり方

Program.cs
RestClient client = new RestClient(baseUrl);
RestRequest request = new RestRequest(Method.POST);

// パラメータやアップロードファイルなどあればセットする

// リクエストBodyの形式を指定
request.RequestFormat = DataFormat.Json;

// Body部分にJson文字列をセット
// 名前部分にapplication/jsonを指定し、パラメータタイプにRequestBodyを指定
request.AddParameter("application/json", jsonString, ParameterType.RequestBody);

client.Execute(request);

まとめ

パラメータとして追加するときに、名前部分に形式を、パラメータのタイプをContentBodyにすればいいだけだった。

2
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?