我正在尝试通过jersey api使用其他网络服务。这是代码:
RestClient.java
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
public class RestClient {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try
{
Client client = Client.create();
WebResource resource = client.resource("http://localhost:8080/RestWebService/rest/UserService/users");
ClientResponse response = resource.accept("application/xml").get(ClientResponse.class);
if(response.getStatus() == 200)
{
System.out.println(response.getEntity(String.class));
}
else
System.out.println("Error : " + response.getStatus());
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
输出:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><users><user><id>1</id><name>Mahesh</name><profession>Scientist</profession></user></users>
我收到XML格式的回复。我想知道如果在泽西api中有一种方法,那么web获取数据的纯文本格式?