3
我捲曲:將cURL帖子轉換爲HTTPclient和HttpPost。獲取HTTP 403錯誤。 [JAVA]
捲曲URL -X POST -d「{ 「東經」: 「5.55」, 「緯度」: 「6.66」, 「地方」: 「世界你好」, 「說明」: 「這個地方是輪椅」}」 -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);
我的捲曲是正確excuted但JAVA代碼保持回報我403錯誤。 請幫助= =