grails - 谷歌地方 API : Adding a new Place: Java/Groovy

标签 grails post groovy location

无法让 POST 工作?怎么了?

注意:这适用于具有自动完成功能的 GET
GET 无需对 url 签名即可工作

  • 我正在按照 Web 服务步骤使用我的“API key ”对 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/

    相关文章:

    grails - grails出现的消息不显示德语

    grails - Grails的KahaDb属性

    php - 如何从 $_POST 数组中删除元素?

    regex - 如何使用 Groovy 的正则表达式获取部分匹配的 bool 值?

    grails - 如何从Grails调用Solr中存在的Rest Api?

    grails - Grails中的messageSource声明在哪里?

    javascript - 将 JS foreach 传递给 JS post 而不使用表单

    ajax - 如何判断帖子是否来自codeigniter中的ajax调用?

    logging - 是否可以在 Jenkins 管道控制台输出中禁用 [Pipeline] 消息?

    groovy - Gradle:为什么从Exec派生的任务看不到自定义项目属性?