私のcURL:
curl URL -X POST -d '{"経度":"5.55", "緯度":"6.66", "場所":"hello world", "説明":"この場所は車椅子でアクセスできます"}' -uユーザー: パスワード -H 'コンテンツ タイプ: アプリケーション/json'
私のJavaコード:
DefaultHttpClient httpclient = new DefaultHttpClient();
httpclient.getCredentialsProvider().setCredentials(
new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
new UsernamePasswordCredentials("user", "password"));
HttpPost httppost = new HttpPost("URL");
httppost.setHeader("Content-type", "application/json");
JSONObject json = new JSONObject();
try {
json.put("longitude", "1");
json.put("latitude", "2");
json.put("place", "3");
json.put("description", "4");
} catch (Exception ex) {
System.err.println(ex.getMessage());
}
try {
StringEntity entity = new StringEntity(json.toString(), HTTP.UTF_8);
// entity.setContentType("application/json");
httppost.setEntity(entity);
HttpResponse resp = httpclient.execute(httppost);
System.out.println(resp.getStatusLine().getStatusCode() + "/"
+ resp.getStatusLine().getReasonPhrase());
} catch (Exception e) {
System.err.println(e.getMessage());
}
System.out.println("SUCCESS: " + result);
cURL は正しく実行されますが、JAVA コードから 403 エラーが返されます。助けてください =.=