1
無法讓POST開始工作?怎麼了?Google Places API:添加新地點:Java/Groovy
注:這適用於帶自動完成 GET作品GET沒有簽署網址
- 我正在關注的Web服務的步驟簽署與我的「API密鑰」的URL 文件說,「客戶端ID 「還是? http://code.google.com/apis/maps/documentation/webservices/
2.Try發送帶有標識的URL的POST數據(試過未簽名的簽名藏漢)
def signedUrl = "https://maps.googleapis.com/maps/api/place/add/json?key=xxxxxkeyxxxxxx&sensor=false&signature=xxxxxxxxxxsignaturexxxxxx"
String postData = "{'location': { 'lat': '-33.8669710','lng': '151.1958750'},'accuracy': '50','name': 'Google Shoes!'}"
URL urlPost = new URL(signedUrl);
URLConnection connection = urlPost.openConnection();
connection.addRequestProperty("Referer", "http://www.mysite.com");
connection.setDoOutput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("CONTENT-TYPE", "text/json");
connection.setRequestProperty("CONTENT-LENGTH", postData.length() + "");
OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
out.write(postData);
out.close();
String line;
StringBuilder builder = new StringBuilder();
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
while((line = reader.readLine()) != null) {
builder.append(line);
}
JSONObject json = new JSONObject(builder.toString());
println json
返回一個403 「java.io.IOException異常:服務器返回的HTTP響應代碼: 403網址:」
Simular的 「Java訪問」 部分中,他們給的一個例子GET http://code.google.com/apis/websearch/docs/#fonje
一個很好的方法來檢查是否JSON是正確的是把它傳遞到HTTPS://www.jsoneditoronline。組織/。它會彈出正確的json。 – Simon 2014-12-25 19:01:41