私はこの問題を抱えていますが、私はなぜそれが間違っているのでしょうか。私はそれを働かせるために書き直さなければならなかったが、それはすべての間違ったにおいがするが、それは動作する。WebApi - PostAsync
だから、500のからstatusCodeが返されたように、これは、私が最初に試したし、それが動作しないものですが、それは応答を待っていなかったので、これはですが、私はそれがとても
[HttpPost]
public async Task<JsonResult> Booking(string model)
{
//do some bits.
var a = new JavaScriptSerializer().Serialize(e);
var booking = new HttpClient();
HttpContent content = new StringContent(a,Encoding.UTF8);
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
HttpResponseMessage response = await booking.PostAsync("https://webapi.domain.com/Booking/Post", content);
var aa = response.StatusCode //500 Internal Error
}
を待つ必要があります私は
[HttpPost]
public async Task<JsonResult> Booking(string model)
{
//do some bits.
var a = new JavaScriptSerializer().Serialize(e);
var booking = new HttpClient();
HttpContent content = new StringContent(a,Encoding.UTF8);
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
HttpResponseMessage response = await booking.PostAsync("https://webapi.domain.com/Booking/Post", content);
var t = new Stopwatch();
while (response.StatusCode ==HttpStatusCode.InternalServerError)
{
t.Start();
var zzzz = response.ReasonPhrase;
if (t.ElapsedMilliseconds >10000)
{
response.StatusCode = HttpStatusCode.RequestTimeout;
t.Stop();
}
}
var aa = response.StatusCode //201 Created
}
を書き直しそして、これは醜い、私の201を動作し、私を返しますが、誰も私に言うと、私が間違ってやっている私を見ることができますか?
コードをフォーマットしてください! –
'booking.PostAsync'とは何ですか?なぜあなたはそこに直接行かないのですか? –
最初のコードがなければ2番目のコードが動作することはほとんどありません。本気ですか?応答ステータスコードはしばらくしても変更されません。 HTTPプロトコルには、送信された応答を「更新」する方法がありません。このタイミングのものは何もしません。 – usr