2017-04-07 48 views
0

我正在使用Google Url縮短API。 縮短URL「http://demos.companyname.com:1339/Google Url更簡短地爲網址提供錯誤Ip

但是當我的東西,如「http://36.186.69.8:1339/」,它返回一個錯誤替換該網址「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"}} 

回答

0

我所知,谷歌網址縮短服務不適用於IP, 它只適用於映射的URL。

檢查下面的鏈接,知道谷歌是否可以縮短你的網址。

https://goo.gl/