0
我试图通过从我的服务器使用Java来使用Microsoft的Bing Spatial Data Service。 (我用这个代码:How to send HTTP request in java?),但它根本不起作用。Java - Bing空间数据服务:<title>对象已移至...</title>
我想要做的:获得纬度和经度从给定ADRESS
public static void main(String[] args) throws IOException {
System.out.println(SendRequete());
}
static String SendRequete(){
String bingMapsKey = "zzzzzzzzzz";
String contentType="text/plain";
String targetURL = "http://dev.virtualearth.net/";
String urlParameters="REST/v1/Locations?countryRegion=France&locality=Paris&postalCode=75001&addressLine=rue%20de%20la%20paix&key=" + bingMapsKey;
System.out.println(targetURL+urlParameters);
try{
HttpURLConnection connection = null;
URL url = new URL(targetURL);
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", contentType);
connection.setRequestProperty("Content-Length",
Integer.toString(urlParameters.getBytes().length));
connection.setRequestProperty("Content-Language", "en-US");
connection.setUseCaches(false);
connection.setDoOutput(true);
//request
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
wr.writeBytes(urlParameters);
wr.close();
//Get Response
InputStream is = connection.getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
StringBuffer response = new StringBuffer(); // or StringBuffer if Java version 5+
String line;
while ((line = rd.readLine()) != null) {
System.out.println(line);
response.append(line);
response.append('\r');
}
rd.close();
return response.toString();
} catch (Exception e) {
e.printStackTrace();
return null;
我一直有同样的结果:
<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="https://msdn.microsoft.com/en-us/library/dd877180.aspx">here</a>.</h2>
</body></html>
</body></html>ed to <a href="https://msdn.microsoft.com/en-us/library/dd877180.aspx">here</a>.</h2>
ml><head><title>Object moved</title></head><body>
如果我复制并粘贴Y上的浏览器,它工作正常...任何想法问题出在哪里