0
我是新來的Java Jersey客戶端API,並想登錄到服務器,如:的Java Jersey客戶端API
POST http:/xxxx.net/auth/login Content-Type: application/json {"login": "xxxxx", "password": "XXXXX"}
你能告訴我這樣一個Java Jersey客戶端爲例API代碼?
我是新來的Java Jersey客戶端API,並想登錄到服務器,如:的Java Jersey客戶端API
POST http:/xxxx.net/auth/login Content-Type: application/json {"login": "xxxxx", "password": "XXXXX"}
你能告訴我這樣一個Java Jersey客戶端爲例API代碼?
// 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);
可能重複http://stackoverflow.com/questions/9462955/authentication-in-jersey – sundar 2012-08-06 12:14:29
你試過Google搜索嗎? http://www.vogella.com/articles/REST/article.html – Tomer 2012-08-06 12:15:28
是的,但我不知道如何將登錄名和密碼添加到WebResource。 – Jancsi 2012-08-06 12:21:50