尝试使用google api maps中的网络服务时出现以下错误:
{ “error_message”:“此API的请求必须通过SSL。”, “结果”:[], “status”:“REQUEST_DENIED” }
用于调用Web服务的URL:
用于调用Web服务的方法:
enter code here
public static String httpPost(String urlStr) throws Exception {
String novaUrl = urlStr.trim();
novaUrl = urlStr.replaceAll(" ", "+");
novaUrl = novaUrl.replaceAll("\r", "");
novaUrl = novaUrl.replaceAll("\t", "");
novaUrl = novaUrl.replaceAll("\n", "");
URL url = new URL(novaUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setUseCaches(false);
conn.setAllowUserInteraction(false);
conn.setRequestProperty("Content-Type", "application/x-www-form-urldecoded");
// Create the form content
OutputStream out = conn.getOutputStream();
Writer writer = new OutputStreamWriter(out, "UTF-8");
writer.close();
out.close();
// Buffer the result into a string
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuilder sb = new StringBuilder();
String line;
while ((line = rd.readLine()) != null) {
sb.append(line);
}
rd.close();
conn.disconnect();
Spanned retorno = Html.fromHtml(sb.toString());
return retorno.toString();
}
如何解决这个问题?
感谢。
答案 0 :(得分:0)
尝试使用此网址。错误只是因为http和https。 https用于安全线路。
现在点击此按钮会出现这样的错误.. 提供的API密钥无效。
为此,只需提供您从Google控制台检索到的正确API密钥。
答案 1 :(得分:0)
here key=my_key Here is the problem, please provide correct API key and you problem will be solved.