我正在从PHP CURL发出PUT请求以下是我的CURL配置细节,PUT的动机 请求是向服务器发送XML请求,服务器是TOMCAT 7
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_PUT, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_INFILE, $xmlreq);
curl_setopt($ch, CURLOPT_INFILESIZE, 2000);
curl_setopt($ch, CURLOPT_HTTPHEADER,array('Content-type: application/xml', 'Content-length:2000')
);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0');
$data = curl_exec($ch);
echo $data;
但我没有得到任何回报
监控后我注意到我发现跟踪错误,但不知道如何解决它
javax.ws.rs.WebApplicationException: java.lang.IllegalArgumentException: Error parsing media type 'application/xml;charset: utf-8'
com.sun.jersey.server.impl.model.HttpHelper.clientError(HttpHelper.java:262)
com.sun.jersey.server.impl.model.HttpHelper.getContentType(HttpHelper.java:88)
com.sun.jersey.server.impl.model.HttpHelper.getContentType(HttpHelper.java:74)
com.sun.jersey.spi.container.ContainerRequest.getMediaType(ContainerRequest.java:544)
com.sun.jersey.spi.container.servlet.WebComponent.filterFormParameters(WebComponent.java:769)
com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:376)
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:451)
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:632)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
root cause
java.lang.IllegalArgumentException: Error parsing media type 'application/xml;charset: utf-8'
com.sun.jersey.core.impl.provider.header.MediaTypeProvider.fromString(MediaTypeProvider.java:77)
com.sun.jersey.core.impl.provider.header.MediaTypeProvider.fromString(MediaTypeProvider.java:50)
javax.ws.rs.core.MediaType.valueOf(MediaType.java:119)
com.sun.jersey.server.impl.model.HttpHelper.getContentType(HttpHelper.java:86)
com.sun.jersey.server.impl.model.HttpHelper.getContentType(HttpHelper.java:74)
com.sun.jersey.spi.container.ContainerRequest.getMediaType(ContainerRequest.java:544)
com.sun.jersey.spi.container.servlet.WebComponent.filterFormParameters(WebComponent.java:769)
com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:376)
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:451)
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:632)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
root cause
java.text.ParseException: Expected separator '=' instead of ':'
com.sun.jersey.core.header.reader.HttpHeaderReader.nextSeparator(HttpHeaderReader.java:112)
com.sun.jersey.core.header.reader.HttpHeaderReader.readParameters(HttpHeaderReader.java:244)
com.sun.jersey.core.impl.provider.header.MediaTypeProvider.valueOf(MediaTypeProvider.java:95)
com.sun.jersey.core.impl.provider.header.MediaTypeProvider.fromString(MediaTypeProvider.java:75)
com.sun.jersey.core.impl.provider.header.MediaTypeProvider.fromString(MediaTypeProvider.java:50)
javax.ws.rs.core.MediaType.valueOf(MediaType.java:119)
com.sun.jersey.server.impl.model.HttpHelper.getContentType(HttpHelper.java:86)
com.sun.jersey.server.impl.model.HttpHelper.getContentType(HttpHelper.java:74)
com.sun.jersey.spi.container.ContainerRequest.getMediaType(ContainerRequest.java:544)
com.sun.jersey.spi.container.servlet.WebComponent.filterFormParameters(WebComponent.java:769)
com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:376)
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:451)
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:632)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
答案 0 :(得分:0)
我会说服务器不支持自定义请求。你应该能够通过POST来做到这一点。您是否尝试过嗅探客户端可以接收和发送的消息?
答案 1 :(得分:0)
设置此行
curl_setopt($ch, CURLOPT_HEADER, 0);
到这一行
curl_setopt($ch, CURLOPT_HEADER, true);
所以你也会得到响应标题。在那里,您将获得有关“错误”的更多信息