我在这方面有困难,我不知道为什么,这一定是我做错了什么。我不得不重写使它工作,但它闻起来完全不对劲,但它的工作。
这就是我第一次尝试的方法,它不起作用,因为500的状态代码被返回了,但这是因为它没有等待响应,我需要它等待。
[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,丑陋,但谁能告诉我并告诉我我做错了什么?
发布于 2016-09-21 13:42:20
服务器有一个与时间相关的错误。当您使用调试器给它足够的时间来避免崩溃时,它就会消失。
异步操作尚未完成时完成的异步模块或处理程序。
看起来像是有异步的东西。
客户端没有出错,while (response.StatusCode ==HttpStatusCode.InternalServerError)循环什么也不做。它甚至不改变服务器的时间。您对调试器的使用可能做到了这一点,在您的解释中,这两种效果都被混淆了。
修复服务器,现在您知道在哪里查找。
https://stackoverflow.com/questions/39614704
复制相似问题