C# 客户端发现响应内容类型为“text/html”,但应为“text/xml”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/490677/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 05:24:43  来源:igfitidea点击:

Client found response content type of 'text/html', but expected 'text/xml'

c#.net-2.0

提问by

I am getting this error:

我收到此错误:

Client found response content type of 'text/html', but expected 'text/xml.

客户端发现响应内容类型为“text/html”,但预期为“text/xml”。

I am adding web reference for live search. When i build the project its Successful. But after that once i enter some text in textbox & enter search button it gives this error. I am Using my local machine & Using .net 2.0 with C#.
Plz help me...
Thanks In Advance...

我正在添加用于实时搜索的网络参考。当我构建项目时,它成功了。但是在那之后,一旦我在文本框中输入一些文本并输入搜索按钮,它就会出现此错误。我正在使用我的本地机器并在 C# 中使用 .net 2.0。
请帮帮我...
提前致谢...

回答by Matt Hamilton

Generally that error means that the service has sent back an (HTML) error message rather than the XML SOAP response that your client was expecting.

通常,该错误意味着服务已发回 (HTML) 错误消息,而不是您的客户端所期望的 XML SOAP 响应。

For web services that you control it's really easy to find the problem, because you can invoke the webmethods by hand in your browser. To diagnose it when it's someone else's service is a little trickier. You might be able to trace into the code for your web reference and inspect the text of the response before the exception is thrown.

对于您控制的 Web 服务,很容易发现问题,因为您可以在浏览器中手动调用 webmethods。当它是其他人的服务时要诊断它有点棘手。您也许能够追踪到您的 Web 参考的代码并在引发异常之前检查响应的文本。

回答by Jon Skeet

As Matt said, it's probably an error page coming back.

正如马特所说,这可能是一个错误页面回来了。

Either use a proxy like Fiddleror a network sniffer like WireSharkto see what the raw response is - that should help you get to the bottom of what's going on.

使用像Fiddler这样的代理或像WireShark这样的网络嗅探器来查看原始响应是什么 - 这应该可以帮助您了解正在发生的事情。

回答by Jon Skeet

In your actual code, replace the line:

在您的实际代码中,替换以下行:

searchRequest.AppID = "APP ID you generated from ...";

with the actual AppID, which should be a long alpha-numeric sequence.

与实际AppID,这应该是一个long alpha-numeric sequence

回答by Chris Nava

I have found Fiddlerto be highly useful in debugging http client server issues. It is a proxy that allows you to intercept and even change the content of the request and response.

我发现Fiddler在调试 http 客户端服务器问题方面非常有用。它是一个代理,允许您拦截甚至更改请求和响应的内容。