博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
android的socket程序中conn.getResponseCode() 为405
阅读量:4212 次
发布时间:2019-05-26

本文共 785 字,大约阅读时间需要 2 分钟。

 最近在写一个Socket程序中,遇到了这个问题,本以为是Android客户端程序的问题,没想到最后问题出现在服务端的Servlet中,也就是我们平时J2ee中经常遇到的405问题。

 具体表现为:

Servlet是普通java写的,client是运行在android模拟器完成,现在情况是Android往Servlet发过去的数据,在Servlet中都可以得到,但是client端在接收Servlet响应的时候报错了!错误:request time failed: java.net.SocketException: Address family not supported by protocol

可以用这种方式做测试:

(我自己的机子:传了两个参数:username,password)

出现HTTP Status 405 - HTTP method GET is not supported by this URL

 原因是:

1、继承自Httpservlet的Servlet没有重写对于请求和响应的处理方法:doGet或doPost等方法,默认调用父类的doGet或doPost等方法。
2、父类HttpServlet的doGet或doPost等方法覆盖了你写的到doGet或doPost等方法。
不管是1或2,父类HttpServlet的doGet或doPost等方法默认实现是返回状态码是405的Http错误表示 对于指定资源请求方法不被允许。
解决方法:
1、子类重写doGet或doPost等方法。
2、在你扩张的Servlet中重写doGet或doPost等方法来处理请求和响应时,不要调用父类的doGet或doPost等方法即去掉supper.doGet(request,response)和super.doPost(request,response);

转载地址:http://uizmi.baihongyu.com/

你可能感兴趣的文章
【IOS游戏开发】之IPA破解原理
查看>>
【一天一道LeetCode】#45. Jump Game II
查看>>
【一天一道LeetCode】#46. Permutations
查看>>
【一天一道LeetCode】#47. Permutations II
查看>>
【一天一道LeetCode】#56. Merge Intervals
查看>>
【一天一道LeetCode】#58. Length of Last Word
查看>>
【一天一道LeetCode】#59. Spiral Matrix II
查看>>
【一天一道LeetCode】#30. Substring with Concatenation of All Words
查看>>
【一天一道LeetCode】#60. Permutation Sequence.
查看>>
【一天一道LeetCode】#113. Path Sum II
查看>>
【一天一道LeetCode】#114. Flatten Binary Tree to Linked List
查看>>
【unix网络编程第三版】阅读笔记(二):套接字编程简介
查看>>
【一天一道LeetCode】#115. Distinct Subsequences
查看>>
【一天一道LeetCode】#116. Populating Next Right Pointers in Each Node
查看>>
【一天一道LeetCode】#117. Populating Next Right Pointers in Each Node II
查看>>
【一天一道LeetCode】#118. Pascal's Triangle
查看>>
同步与异步的区别
查看>>
IT行业--简历模板及就业秘籍
查看>>
JNI简介及实例
查看>>
JAVA实现文件树
查看>>