5

我正在尝试使用 Web 服务从服务器检索数据。我按照http://googcloudlabs.appspot.com/codelabexercise5.html中指定的教程进行操作,当然我已经修改了原始代码以满足我的需求。

现在我收到这样的错误: Unsupported Content-Type: text/html; charset=UTF-8 支持的有:[text/xml]

为了查看完整的错误,我在获取数据时编写了一个新的错误函数:

var errorFn = function(e){

    for(var p in e){
    alert(e[p]);
    }
}

var successFn = function(resp){

    var data='';
    if(resp){
    //getting the data from the response object
        data=resp.data;         
    }

        //Some other code here... 

}

getData("/entity",null,successFn,errorFn);

浏览器警告错误对象:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>Error 500 Unsupported Content-Type: text/html; charset=UTF-8 Supported ones are: [text/xml]</title>
</head>
<body><h2>HTTP ERROR 500</h2>
<p>Problem accessing /vehicle. Reason:
<pre>    Unsupported Content-Type: text/html; charset=UTF-8 Supported ones are: [text/xml]</pre></p><h3>Caused by:</h3><pre>com.sun.xml.internal.ws.server.UnsupportedMediaException: Unsupported Content-Type: text/html; charset=UTF-8 Supported ones are: [text/xml]

    at com.sun.xml.internal.ws.encoding.StreamSOAPCodec.decode(Unknown Source)

    at com.sun.xml.internal.ws.encoding.StreamSOAPCodec.decode(Unknown Source)

    at com.sun.xml.internal.ws.encoding.SOAPBindingCodec.decode(Unknown Source)

    at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.process(Unknown Source)

    at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.processRequest(Unknown Source)

    at com.sun.xml.internal.ws.transport.DeferredTransportPipe.processRequest(Unknown Source)

    at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Unknown Source)

    at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Unknown Source)

    at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Unknown Source)

    at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Unknown Source)

    at com.sun.xml.internal.ws.client.Stub.process(Unknown Source)

    at com.sun.xml.internal.ws.client.sei.SEIStub.doProcess(Unknown Source)

    at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(Unknown Source)

    at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(Unknown Source)

    at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(Unknown Source)

    at $Proxy32.getAllVehicles(Unknown Source)

    at com.google.appengine.codelab.soap.client.VehicleServlet.doGet(VehicleServlet.java:52)

    at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)

    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)

    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)

    at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:35)

    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)

    at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:60)

    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)

    at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)

    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)

    at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:125)

    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)

    at com.google.appengine.tools.development.BackendServersFilter.doFilter(BackendServersFilter.java:97)

    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)

    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)

    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)

    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)

    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)

    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)

    at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:94)

    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)

    at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:370)

    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)

    at org.mortbay.jetty.Server.handle(Server.java:326)

    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)

    at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)

    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)

    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)

    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)

    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)

    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)

</pre>
<hr /><i><small>Powered by Jetty://</small></i><br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                
<br/>                                                

</body>
</html>

有人帮我解决这个问题??

预先感谢!

4

7 回答 7

6

在类的头部添加以下代码:

@BindingType("http://java.sun.com/xml/ns/jaxws/2003/05/soap/bindings/HTTP/")

然后重启你的服务器。

于 2013-03-09T08:00:14.467 回答
3

这个错误发生在我身上,原因是对 web 服务的调用是对一个无效的主机进行的,所以 web 服务器响应的是 http 错误消息而不是 xml soap 消息。

于 2015-10-15T18:09:56.917 回答
1

我的情况,同样的错误,但不同的原因:

端口未在 wsdl 中指定,服务器将其返回给 Java 服务“生成器”。因此,Web 服务器用一个主页回答了 SOAP 调用,该主页当然不是文本/XML,而是文本/html。

将端口添加到 wsdl 解决了这个问题。

于 2013-05-13T11:27:16.653 回答
0

Try other clients . in my case the problem occurs in jdeveloper 11.1.2.0 (Http analyser as client) and solved by Jdeveloper 11.1.2.3 (Http analyser as client)

This problem comes from request Content-Type

于 2013-10-20T13:47:03.177 回答
0

我也遇到过这个问题,最后发现是服务器造成的。

该服务器基于 Node.js 构建,同时使用两个包multerformidable解析“multipart/form-data”类型的表单数据。这导致了冲突:实际的表单解析器formidable无法获取原始表单数据,因为multer已经处理了该数据并获得了干净的内容。我们删除multer了,然后问题就解决了。

于 2015-01-27T03:52:20.853 回答
0

当编写 SOAP 请求并且提供的内容编码/格式不正确/无法访问时,也会发生此错误。这可能不是您的情况,但如果其他人在发送请求之前遇到相同的错误,这意味着用于撰写邮件本身或其附件的数据编码不正确、格式不正确或通常无法访问。

于 2013-02-14T16:38:13.890 回答
0

很简单:您的客户端(浏览器?)正在发送数据,因为Content-Type: text/html它应该是Content-Type: application/soap+xml(对于旧的 SOAP也是Content-Type: text/xml)。

因此,如果您手动发出请求,则应将Content-Type标头添加到 HTTP 请求中。

于 2012-08-29T06:02:31.020 回答