我试着做球衣客户,但我犯了个错误。这是我的密码:
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));
}
} 排成一行
String response = webResource.path("hello").accept(MediaType.TEXT_PLAIN).get(String.class);有一个错误:类型中的方法接受(MediaType[])不适用于参数(字符串)
可能是什么原因?我怎么才能修好它?
谢谢
发布于 2015-02-26 17:08:25
java编译器是一个旧的。我更新它,现在一切都很好。
谢谢你的答复
发布于 2015-02-25 07:39:12
创建m对象并将其作为参数传递以接受:
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);https://stackoverflow.com/questions/28041521
复制相似问题