ICS上的Http get异常:目标主机不得为空

4

我在ICS上遇到了这个异常,而在2.2上它运行良好。

java.lang.IllegalStateException: Target host must not be null, or set in parameters. scheme=null, host=null, path=http://maps.googleapis.com/maps/api/geocode/json?latlng=32.0692342,34.7952296&sensor=true

这是我的代码:

        HttpGet request = new HttpGet(URLEncoder.encode(requestUrl, "UTF-8"));
        HttpResponse response;
        response = mHttpClient.execute(request);

你能否也发布请求URL?它似乎不是正确的格式。 - kosa
1个回答

10

去掉URLEncoder.encode的调用,它是不必要的

需要对URL参数进行编码,例如:

String url = "http://maps.googleapis.com/maps/api/geocode/json?latlng="+URLEncoder.encode("32.0692342,34.7952296")+"&sensor="+URLEncoder.encode("true")

但是如果我需要在此之前对URL进行编码呢? 10-17 16:29:53.235: W/System.err(18170): java.net.URISyntaxException: 查询中的非法字符索引为58:http://maps.googleapis.com/maps/api/geocode/json?address=, בדיקה,&sensor=true - meh
4
只需对URL参数进行编码,而不需要对整个URL进行编码。 - Daniel Fekete

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接