首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WebResource类型中的方法接受(WebResource)不适用于参数(字符串)。

WebResource类型中的方法接受(WebResource)不适用于参数(字符串)。
EN

Stack Overflow用户
提问于 2015-01-20 09:16:07
回答 2查看 2.4K关注 0票数 0

我试着做球衣客户,但我犯了个错误。这是我的密码:

代码语言:javascript
复制
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import javax.ws.rs.core.MediaType;

public class Test {
    public static void main(String[] args) {
        // Create Client and Handle to web resources
        String BASE_URI = "http://localhost:8080/HelloWorldWebapp/resources";
        Client client = Client.create();
        WebResource webResource = client.resource(BASE_URI);

    // send a GET request with Accept header set to "text/plain"
    String response = webResource.path("hello").accept(MediaType.TEXT_PLAIN).get(String.class);
    System.out.println(response);

    // send GET request with a query parameter value for 'name'
    response = (String) webResource.path("hello").queryParam("name", "Pranabh").get(String.class);
    System.out.println(response);

    // send GET request to /hello without any query param
    response = (String) webResource.path("hello").get(String.class);
    System.out.println(response);

    // send GET request to /hello/{name}
    response = webResource.path("hello").path("Ranjita").accept(MediaType.TEXT_PLAIN).get(String.class);
    System.out.println(response);

    // send a GET request and get the response encapsulate in ClientResponse
    ClientResponse clientResponse = (ClientResponse) webResource.path("hello").get(ClientResponse.class);
    System.out.println(clientResponse.getEntity(String.class));
}

} 

排成一行

代码语言:javascript
复制
String response = webResource.path("hello").accept(MediaType.TEXT_PLAIN).get(String.class);

有一个错误:类型中的方法接受(MediaType[])不适用于参数(字符串)

可能是什么原因?我怎么才能修好它?

谢谢

EN

回答 2

Stack Overflow用户

发布于 2015-02-26 17:08:25

java编译器是一个旧的。我更新它,现在一切都很好。

谢谢你的答复

票数 1
EN

Stack Overflow用户

发布于 2015-02-25 07:39:12

创建m对象并将其作为参数传递以接受:

代码语言:javascript
复制
MediaType[] m = new MediaType[]{MediaType.TEXT_HTML_TYPE, 
                        MediaType.APPLICATION_XML_TYPE, MediaType.TEXT_XML_TYPE};

String response = webResource.path("hello").accept(m).get(String.class);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28041521

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档