风暴之路休息 api Java
Stormpath Rest api Java
有人可以帮我在 java 中以 httpRequest 的形式写这个吗?我试过很多次都失败了。我不知道为什么,但我就是做不对 =(
curl -X POST --user $YOUR_API_KEY_ID:$YOUR_API_KEY_SECRET \
-H "Accept: application/json" \
-H "Content-Type: application/json;charset=UTF-8" \
-d '{
"favoriteColor": "red",
"hobby": "Kendo"
}' \
"https://api.stormpath.com/v1/accounts/cJoiwcorTTmkDDBsf02bAb/customData"
(自定义数据必须为 json 格式)
如有任何帮助,我们将不胜感激。 =)
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost(
"https://api.stormpath.com/v1/accounts/cJoiwcorTTmkDDBsf02bAb/customData");
String credentials = apiKey.getId() + ":" + apiKey.getSecret();
postRequest.setHeader("Authorization", "Basic " + Base64.encodeBase64String(credentials.getBytes("UTF-8")));
postRequest.setHeader("Accept", "application/json");
StringEntity input = new StringEntity("{\"favoriteColor\":\"red\",\"hobby\":\"Kendo\"}");
input.setContentType(ContentType.APPLICATION_JSON.toString());
postRequest.setEntity(input);
HttpResponse response = httpClient.execute(postRequest);
System.out.println(response);
有人可以帮我在 java 中以 httpRequest 的形式写这个吗?我试过很多次都失败了。我不知道为什么,但我就是做不对 =(
curl -X POST --user $YOUR_API_KEY_ID:$YOUR_API_KEY_SECRET \
-H "Accept: application/json" \
-H "Content-Type: application/json;charset=UTF-8" \
-d '{
"favoriteColor": "red",
"hobby": "Kendo"
}' \
"https://api.stormpath.com/v1/accounts/cJoiwcorTTmkDDBsf02bAb/customData"
(自定义数据必须为 json 格式)
如有任何帮助,我们将不胜感激。 =)
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost(
"https://api.stormpath.com/v1/accounts/cJoiwcorTTmkDDBsf02bAb/customData");
String credentials = apiKey.getId() + ":" + apiKey.getSecret();
postRequest.setHeader("Authorization", "Basic " + Base64.encodeBase64String(credentials.getBytes("UTF-8")));
postRequest.setHeader("Accept", "application/json");
StringEntity input = new StringEntity("{\"favoriteColor\":\"red\",\"hobby\":\"Kendo\"}");
input.setContentType(ContentType.APPLICATION_JSON.toString());
postRequest.setEntity(input);
HttpResponse response = httpClient.execute(postRequest);
System.out.println(response);