0

我正在使用 Google Url 缩短 API。缩短 URL “ http://demos.companyname.com:1339/

但是当我用“ http://36.186.69.8:1339/ ”之类的东西替换这个 URL“ http://demos.companyname.com:1339/ ”时,它会返回一个错误。

如何解决这个问题呢?

我的 URL 缩短代码是:

公共 JSONObject getJSONFromUrl(字符串地址,字符串 longUrl){

    // Making HTTP request
    try {
        // DefaultHttpClient
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(address);

        httpPost.setEntity(new StringEntity("{\"longUrl\":\""+ longUrl+"\"}"));
        httpPost.setHeader("Content-Type", "application/json");
        HttpResponse httpResponse = httpClient.execute(httpPost);

        HttpEntity httpEntity = httpResponse.getEntity();
        is = httpEntity.getContent();

    } catch (IOException e) {
        e.printStackTrace();
    }

    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                is, "iso-8859-1"), 8);
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            sb.append(line).append("\n");

        }
        is.close();
        Log.e("getJSONFromUrl: ", sb.toString());
        json = sb.toString();
        Log.e("JSON", json);
    } catch (Exception e) {
        Log.e("Buffer Error", "Error converting result " + e.toString());
    }

    // Parse the String to a JSON Object
    try {
        jObj = new JSONObject(json);
    } catch (JSONException e) {
        Log.e("JSON Parser", "Error parsing data " + e.toString());
    }
    // Return JSON String
    return jObj;

}

错误响应:

   {"error":{"errors":
         [{"domain":"global","reason":"invalid","message":"InvalidValue","locationType":"parameter","location":"resource.longUrl"}],"code":00,"message":"Invalid Value"}}
4

1 回答 1

0

据我所知,谷歌 URL 缩短器不适用于 IP,它仅适用于映射 URL。

检查下面的链接以了解谷歌是否可以缩短您的网址。

https://goo.gl/

于 2017-04-07T08:51:40.953 回答