我想将此网址称为http://nominatim.openstreetmap.org/search?q=ΠΑΡΙΣΙ& format = json& polygon = 1& addressdetails = 1
其中0ΠΑΡΙΣΙ是我从JSP获得的参数,
确保一切正确我甚至将文件写入URL
String urls = "http://nominatim.openstreetmap.org/search?q=" + URLEncoder.encode(addressString.trim(), "UTF-8") + "&format=json&polygon=1&addressdetails=1";
File fileDir = new File("c:\\temp\\testUTF-82.txt");
Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileDir), "UTF8"));
out.append(urls);
out.flush();
out.close();
URL url = new URL(urls);
HttpURLConnection uc = (HttpURLConnection) url.openConnection();
uc.setRequestMethod("GET");
uc.setRequestProperty("Accept:", "application/json");
uc.setRequestProperty("Accept-Charset:", "UTF-8");
uc.setRequestProperty("Accept-Charset", "UTF-8");
uc.setRequestProperty("Content-Type:","application/x-www-form-urlencoded;charset=utf-8");
uc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
uc.connect();
但我得到了这个奇怪的错误:
Response: '406: Not Acceptable' for url: 'http://nominatim.openstreetmap.org/search?q= %CE%A0%CE%91%CE%A1%CE%99%CE%A3%CE%99&format=json&polygon=1&addressdetails=1'
这是文件testUTF-82.txt中的字符串:
http://nominatim.openstreetmap.org/search?q=%CE%A0%CE%91%CE%A1%CE%99%CE%A3%CE%99& format = json& polygon = 1& addressdetails = 1
答案 0 :(得分:1)
该链接在浏览器中打开。它返回一个JSON响应,其中包含有效的OpenStreetMap输出和HTTP 200状态代码。
您的客户端正在接收HTTP 406状态代码。 This page给出了状态代码的说明。指示的错误原因是服务器上支持的响应格式与客户端上可接受的响应格式之间缺乏匹配。
以下标题与可接受的响应格式相关:
您可以尝试明确设置以下请求标头:
“接受:application / json” “Accept-Charset:UTF-8”