通过http方式请求客户公司的接口,出现的几个问题以及解决方法:
1.java.lang.NoClassDefFoundError: org/apache/http/params/SyncBasicHttpParams
at org.apache.http.impl.client.DefaultHttpClient.createHttpParams(DefaultHttpClient.java:161)
是因为httpcore-4.1-alpha1.jar包没有导入,导入后异常解除
2.java.lang.VerifyError: Cannot inherit from final class
可能包有冲突,http请求需要的包如下:
commons-logging-1.1.1.jar
commons-codec-1.4.jar
httpclient-4.1.2.jar
httpcore-4.1-alpha1.jar(我这边是因为httpcore-4.0.jar和httpcore-4.1-alpha1.jar冲突了,删掉版本低的)
问题已解决
3.Exception in thread "main" java.lang.IllegalStateException: Target host must not be null, or set in parameters.
出现这个问题可能是你请求的路径不完整,完整如下:必须加上http://
HttpGet httppost = new HttpGet("http://test.service.cc");
以上是我遇到的问题,在百度搜索不到什么答案,谷歌搜索有一个好的网站:http://stackoverflow.com/
你可以搜到自己类似的问题并得到解答
附上下载jar包的网站:http://www.findjar.com/index.x