0

我是 Java Jersey Client API 的新手,想登录到服务器,例如:

POST http:/xxxx.net/auth/login

Content-Type: application/json
{"login": "xxxxx", "password": "XXXXX"}

你能给我看一个这样的 Java Jersey 客户端 API 代码的例子吗?

4

1 回答 1

1
// create a Jersey client
Client client = Client.create();

// create the JSON as a Map 
Map<String, String> data = new HashMap<String, String>();
data.put("login", "xxxxx");
data.put("password", "xxxxx");

// post to the resource with APPLICATION_JSON_TYPE and it will be converted to JSON for you
client.resource("http://xxxx.net/auth/login")
      .type(MediaType.APPLICATION_JSON_TYPE)
      .post(data);
于 2012-11-08T07:25:36.567 回答