[英]Getting exception near DefaultHttpClient when i am trying to access restful wcf service in java.Here is my code
Getting exception near DefaultHttpClient when i am trying to access restful wcf service in java.Here is my code: 当我尝试访问Java中的静态WCF服务时,在DefaultHttpClient附近获取异常。这是我的代码:
public String rest(String SERVICE_URI){
String a="";
try{
HttpGet request = new HttpGet(SERVICE_URI + "/hello");
request.setHeader("Accept", "application/json");
request.setHeader("Content-type", "application/json");
**DefaultHttpClient httpClient = new DefaultHttpClient();**
HttpResponse response = httpClient.execute(request);
HttpEntity responseEntity = response.getEntity();
// Read response data into buffer
char[] buffer = new char[(int)responseEntity.getContentLength()];
InputStream stream = responseEntity.getContent();
InputStreamReader reader = new InputStreamReader(stream);
reader.read(buffer);
stream.close();
JSONArray plates = new JSONArray(new String(buffer));
a=plates.toString();
}catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return a;
}
the exception is : 例外是:
Exception in thread "main" java.lang.VerifyError: (class:
org/apache/http/impl/client/DefaultHttpClient, method: createHttpParams signature: ()Lorg/apache/http/params/HttpParams;) Incompatible argument to function
org / apache / http / impl / client / DefaultHttpClient,方法:createHttpParams签名:()Lorg / apache / http / params / HttpParams;)函数的参数不兼容
Please can anyone help me ...Thank you. 请任何人能帮助我...谢谢。
This seems to be a class loader problem. 这似乎是一个类加载器问题。 Your code is probably compiled against one jar file (containing the HTTP client stuff).
您的代码可能是针对一个jar文件(包含HTTP客户端内容)编译的。 But when it's run, a different, incompatible jar file with the same class is used.
但是在运行时,将使用具有相同类的另一个不兼容的jar文件。
Are you running the code within an application server? 您是否在应用程序服务器中运行代码? If yes, the application server might already have a different version of the Apache Http client libraries in a shared location that takes precedence.
如果是,则应用程序服务器可能已经在优先位置的共享位置中具有不同版本的Apache Http客户端库。
I would guess that your problem might be related to the fact that you are setting a Content-Type header for a GET. 我猜您的问题可能与您为GET设置Content-Type标头有关。 GET requests should not include Content-Type headers.
GET请求不应包含Content-Type标头。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.