简体   繁体   English

当我尝试访问Java中的静态WCF服务时,在DefaultHttpClient附近获取异常。这是我的代码

[英]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.

相关问题 我没有使用angularjs将数据传输到我的宁静Web服务上 - I am not getting data on to my restful web service using angularjs 为什么我在尝试从文本文件中读取时收到错误消息“在java代码中未报告的异常Java.io”? - Why am I getting an error message “unreported exception Java.io in a java code when trying to read from a text file”? 当我尝试运行我的代码时,我得到“ java.lang.Exception:java.lang.IllegalStateException” - I am getting “java.lang.Exception: java.lang.IllegalStateException” when i try to run my code 为什么我在Java中收到死代码警告? - Why am I getting dead code warning here in java? 为什么我不推荐使用DefaultHttpClient? - Why I am getting DefaultHttpClient is deprecated? 当尝试根据给定查询查找给定字符串中的子字符串计数时,有人能告诉我我在 Java 代码中做错了什么吗? - Can someone tell me what am I doing wrong here in my Java code when trying to find count of substrings in given string according to given queries? 为什么我在这里得到空异常? - Why am I getting null exception here? 当我尝试从 Outlook Web 访问发送邮件时出现 java 运行时异常 - I get java runtime exception when I am trying to send mail from outlook web access 不确定为什么尝试调用我的方法时会出现异常 - Not sure why I am getting an exception when trying to call my method 为什么在尝试创建此屏幕(窗口)时出现异常? - Why am I getting an exception when trying to create this Screen(window)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM