【jersey 模拟Http请求】

1、代码如下:

package cn.com;

import javax.ws.rs.core.MediaType;

import com.sun.jersey.api.client.Client;

import com.sun.jersey.api.client.ClientResponse;

import com.sun.jersey.api.client.WebResource;

public class JerseyDemo {

/**

<dependency>

    <groupId>com.sun.jersey</groupId>

    <artifactId>jersey-client</artifactId>

    <version>1.19</version>

</dependency>

*/

public static void main(String[] args) {

String restURI = "http://gaojingsong.iteye.com";

 Client c = Client.create();

 WebResource webResource = c.resource(restURI+"/blog/2342122");

 ClientResponse response = webResource.type(MediaType.APPLICATION_FORM_URLENCODED)

          .get(ClientResponse.class);

 System.out.println(response.getEntity(String.class));

}

}

2、验证



 

猜你喜欢

转载自gaojingsong.iteye.com/blog/2342157