简体   繁体   English

使用 httpClient.PostAsync Result ="{尚未计算}"的问题

[英]Problem using httpClient.PostAsync Result = "{Not yet computed}"

im trying to upload a file using POST, normally it works well and i have no problem but there is a case where the file has to be separated in various parts to get uploaded (its something that is made in the API side so the method in my code for upload the file is the same than the normal upload) when i try to do this i recieve this response Id = 3129, Status = WaitingForActivation, Method = "{null}", Result = "{Not yet computed}" i think is because this response takes longer and maybe my side doenst wait until is ready this is the code我正在尝试使用 POST 上传文件,通常它运行良好,我没有问题,但有一种情况,文件必须在各个部分分开才能上传(它是在 API 端制作的,因此方法在我上传文件的代码与正常上传相同)当我尝试执行此操作时,我收到此响应Id = 3129, Status = WaitingForActivation, Method = "{null}", Result = "{Not yet computed}"我认为是因为这个响应需要更长的时间,也许我的一方会等到准备好这是代码

var httpResponse2 = httpClient.PostAsync(url + "/" + api + "/" + coin + "/transaction/multiple-transaction-woc", content);
responseContent2 = await httpResponse2.Result.Content.ReadAsStringAsync();

when it reach responseContent2 it breaks because Result is null当它到达responseContent2它会中断,因为 Result 为 null

ive tryed var httpResponse2 = httpClient.PostAsync(url + "/" + api + "/" + coin +"/transaction/multiple-transaction-woc", content).wait;var httpResponse2 = httpClient.PostAsync(url + "/" + api + "/" + coin +"/transaction/multiple-transaction-woc", content).wait; but it doenst work and using await break it too.但它确实有效,并且使用 await 也会破坏它。

when i use postman works just fine.当我使用邮递员时效果很好。

Sorry for my english and thank you for any help.对不起我的英语,感谢您的帮助。

You should await the actual HTTP call first, and then process any content asynchronously as well.您应该首先等待实际的 HTTP 调用,然后异步处理任何内容。

Your final code should look a bit like this:您的最终代码应如下所示:

var httpResponse2 = await httpClient.PostAsync(url + "/" + api + "/" + coin + "/transaction/multiple-transaction-woc", content);
responseContent2 = await httpResponse2.Content.ReadAsStringAsync();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM