0
我在.NetCore 1.1中创建了一个WebAPI,需要调用一个外部服务。当我与dotnet run
运行它,它完美的作品,但是当我使用泊坞我得到一个.NetCore PostAsync和GetAsync不支持Docker
一个或多个错误发生。 (同时发送 请求时出错。)
这是我Post方法:
public static string Post(string url, string jsonObject, string serviceName)
{
// opening a connection to the microservice
using (HttpClient client = new HttpClient())
using (HttpResponseMessage response = client.PostAsync(url, new StringContent(jsonObject, Encoding.UTF8, "application/json")).Result)
{
LogWrapper.SafeInfo(LoggingEvents.SERVICECALLER_GETSERVICESRESPONSE, "Let's test if we get an OK response from " + serviceName);
// we'll throw an exception in case status code is different from 200
response.EnsureSuccessStatusCode();
LogWrapper.SafeInfo(LoggingEvents.SERVICECALLER_GETSERVICESRESPONSE, "We got an OK response from " + serviceName);
using (HttpContent responseContent = response.Content)
{
return responseContent.ReadAsStringAsync().Result;
}
}
}
的误差符合client.PostAsync
抛出。 GET方法中发生同样的错误。
我已经检查了URL和参数。
更令人感兴趣的是它只发生在我的Docker容器中运行我的应用程序时。当我运行没有Docker的应用程序时,它工作得很好。
感谢您的帮助。
您需要更深入地记录异常。检查它是否有内部异常提供附加信息。目前,您的描述过于宽泛。码头网络无法访问1000个目标主机的1个可能原因。 –
运行怎么样?您需要提供更多信息。你正在运行的命令。发布到的URL是什么。此URL正在运行。记录每个涉及的服务。什么Docker版本。如果Docker是本地的,它是如何安装/运行的。 –
旁注:你使用'async'方法以同步的方式阻塞调用'.Result',这是一个糟糕而危险的做法。在这种情况下使用'await' – VMAtm