我正在使用Google Url缩短API。 缩短网址“http://demos.companyname.com:1339/”
但是当我用“http://demos.companyname.com:1339/”替换此网址“http://36.186.69.8:1339/”时,它会返回错误。
如何解决这个问题?
我的网址缩短代码为:
public JSONObject getJSONFromUrl(String address,String 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 :(得分:0)