python 2.6 请求servlet报错
我的sendToJava.py中的程序如下:
#-*- coding:utf-8 -*- ps_url = "http://10.143.239.253:8080/secondJavaDemo/TestServlet?account=guopengfei&receiver=0001" filename="E:PythonWorkTestdefdoc.xml" file = open(filename, 'r') content = file.read() import urllib2 req = urllib2.Request(url=ps_url, headers = {'Content-type':'text/xml'}) req.add_data(content) rep = urllib2.urlopen(req) print rep.read()
package com.demo; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class TestServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { System.out.println("执行get方阿飞"); String string = req.getParameter("account"); System.err.println("接收到的数据为:"+string); resp.setContentType("text/xml;charSet=utf-8"); super.doGet(req, resp); } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { System.out.println("执行post方阿飞"); String string = req.getParameter("account"); System.err.println("接收到的数据为:"+string); super.doPost(req, resp); } }
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <display-name></display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <servlet> <servlet-name>XmlRpcServer</servlet-name> <servlet-class>com.demo.TestServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>XmlRpcServer</servlet-name> <url-pattern>/TestServlet</url-pattern> </servlet-mapping> </web-app>
C:Python27python.exe C:/Users/huipu/Desktop/testpythonfile/sendToJava.py Traceback (most recent call last): File "C:/Users/huipu/Desktop/testpythonfile/sendToJava.py", line 15, in <module> rep = urllib2.urlopen(req) File "C:Python27liburllib2.py", line 154, in urlopen return opener.open(url, data, timeout) File "C:Python27liburllib2.py", line 437, in open response = meth(req, response) File "C:Python27liburllib2.py", line 550, in http_response 'http', request, response, code, msg, hdrs) File "C:Python27liburllib2.py", line 475, in error return self._call_chain(*args) File "C:Python27liburllib2.py", line 409, in _call_chain result = func(*args) File "C:Python27liburllib2.py", line 558, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 405: Method Not Allowed 进程已结束,退出代码1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
引用来自“蓝水晶飞机”的评论