System.Net.Http.HttpRequestException:服务器返回了无效或无法识别的响应。在System.Net.Http.CurlResponseHeaderReader.ReadHeader(String&headerName,String&headerValue)中。在System.Net.Http.CurlHandler.MultiAgent.CurlReceiveHeadersCallback(IntPtr buffer,UInt64 size,UInt64 nitems,IntPtr context)中结束前一个位置引发异常的堆栈跟踪---。在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)中,等待任务的处理非成功和调试器通知。在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)中。
这是使Post调用的代码:
Uri uri = new Uri(ServiceConfiguration.SERVICE_URL);
string sSOAPResponse = String.Empty;
HttpClient hc = new HttpClient();
hc.DefaultRequestHeaders.Add("SOAPAction", oRequest.Action);
var content = new StringContent(oRequest.RequestMessage, Encoding.UTF8, "text/xml");
try
{
using (HttpResponseMessage response = await hc.PostAsync(uri, content))
{
sSOAPResponse = await response.Content.ReadAsStringAsync();
(...)
}
我猜测这是因为我的头文件定义导致的。我也尝试在Linux控制台上使用curl进行请求,并且得到了预期的响应。我的头文件定义有问题吗?
使用CURL命令示例成功(源)
SOAP UI请求(原始):curl --header "Content-Type: text/xml;charset=UTF-8" --header "SOAPAction: ACTION_YOU_WANT_TO_CALL" --data @FILE_NAME URL_OF_THE_SOAP_WEB_SERVICE_ENDPOINT
POST http://xxx/xxx/xxx.php HTTP/1.1 Accept-Encoding: gzip,deflate Content-Type: text/xml;charset=UTF-8 SOAPAction: "http://xxx/xxx/xxx.php/userLogin" Content-Length: 488 Host: xxx Connection: Keep-Alive User-Agent: Apache-HttpClient/4.1.1 (java 1.5