0
からの応答を取得、私はポストをやっているし、応答は以下のようにRESTのAPIと通信するためのHttpClientを使用します:最良の方法とREST API'S
public static string PostToAPI(string value)
{
var payload = new APIModel
{
CommandText = value
};
var stringPayload = JsonConvert.SerializeObject(payload);
var httpContent = new StringContent(stringPayload,Encoding.UTF8,"application/json");
System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();
HttpResponseMessage message=client.PostAsync("https://testAPI/test",httpContent).Result if (message.IsSuccessStatusCode)
{
string result = message.Content.ReadAsStringAsync().Result;
return result;
}
return string.Empty;
}
は、他の代替またはそれを行う最善の方法は何ですか?
下http://stackoverflow.com/questions/9620278/how-do-i-make-calls-to-a-rest-api-using-c – Adwaenyth
の可能性の重複を試してみてください:)本当に使いやすい。非同期でも呼び出すことができます。 –