无法让 POST 工作?怎么了?
注意:这适用于具有自动完成功能的 GET
GET 无需对 url 签名即可工作
文档仍然说“客户 ID”?
http://code.google.com/apis/maps/documentation/webservices/
2.尝试使用签名的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 响应代码:URL 的 403:”
类似于他们给出的 GET 示例下的“Java Access”部分
http://code.google.com/apis/websearch/docs/#fonje
最佳答案
好的解决了。
无需签署 URL
postData 字符串错误
本来应该
String postData = "{\"location\": { \"lat\": -33.8669710,\"lng\": 151.1958750},\"accuracy\": 50,\"name\": \"Google Shoes!\", \"types\":[\"bar\"]}"
关于grails - 谷歌地方 API : Adding a new Place: Java/Groovy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6001472/