Http get exception目标主机在ICS上不能为空

meh*_*meh 3 java android http-get google-api

我在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
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

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

Dan*_*ete 9

取消URLEncoder.encode通话,不需要

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

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

  • 您只需要编码URL参数,而不是整个URL (4认同)