HttpClientとHttpResponseMessageを使用して2つの文字列でHTTP POST呼び出しを実行しようとしています。HttpClientとHttpResponseMessageを使用した2つの文字列によるPostAsync
はここでポストを呼び出し私のコードです:
public async Task Convert()
{
string url = "http://localhost:5000/convert/files";
string stringValue1 = "test1";
string stringValue2 = "test2";
var x = await ConvertFiles(stringValue1, stringValue2, url);
}
public async static Task<string> ConvertFiles(string s1, string s2, string webAddress)
{
HttpClient client = new HttpClient();
StringContent sc = new StringContent("");
HttpResponseMessage response = await client.PostAsync(webAddress, sc);
string content = await response.Content.ReadAsStringAsync();
Console.WriteLine("Result: " + content);
return content;
}
私はStringContentを使用する必要があると考えているが、私は(それが空である理由である)かどうかはわかりません。私はただのHttpClientとHttpResponseMessage使用を開始しました
[HttpPost("/mshdf/import")]
public string ConvertFiles([FromBody]string s1, [FromBody]string s2)
{
Console.WriteLine("string1: " + s1);
Console.WriteLine("string2: " + s2);
return "woo";
}
:
は、ここに私のHttpPost呼び出します。今、呼び出しは発生しません - 私はこれが両方の文字列s1とs2を適切に送信していないという事実によると推測しています。
一つだけ '[FromBody]'パラメータは、(すべての後に一つだけの体があります)許可されています。 2つの文字列プロパティを持つクラスを作成して送信するか、StringContentの代わりにFormUrlEncodedコンテンツを送信することができます。 – Crowcoder
ありがとう!私は正式な答えを書いて、あなたに信用します。 – Roka545