主机名可能不Htt的presponse为Android执行空

主机名可能不Htt的presponse为Android执行空

本文介绍了主机名可能不Htt的presponse为Android执行空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到的错误目标主机不能为空,或参数设置。

I get the error "Target host must not be null, or set in parameters".

  • 有上网权限在我的清单文件
  • 我已经把HTTP://我的网址前
  • 连接code中的网址
  • I DO have Internet permission in my manifest file
  • I have put 'http://' before my Url
  • I DO encode the URL

这是我的code:

   String url = "http://maps.google.com/maps/api/directions/json?origin=1600 Pennsylvania Avenue NW, Washington, DC 20500&destination=1029 Vermont Ave NW, Washington, DC 20005&sensor=false";
   HttpClient httpclient = new DefaultHttpClient();
   String goodURL = convertURL(url);//change weird characters for %etc
   HttpPost httppost = new HttpPost(goodURL);
   HttpResponse response = httpclient.execute(httppost);

在5日线(上面最后一行),我的程序会抛出异常。这里是确切的错误:

In 5th line (last line above), my program throws an exception. here is the exact error:

java.lang.IllegalArgumentException: Host name may not be null

我做EN code我的方法串convertURL ...

goodURL = <$c$c>http://maps.google.com/maps/api/directions/json?origin=3%20Cedar%20Ave%2c%20Highland%20Park%2c%20NJ%2008904&destination=604%20Bartholomew%20Road%2c%20Piscataway%2c%20New%20Jersey%2008854&sensor=false

goodURL= http://maps.google.com/maps/api/directions/json?origin=3%20Cedar%20Ave%2c%20Highland%20Park%2c%20NJ%2008904&destination=604%20Bartholomew%20Road%2c%20Piscataway%2c%20New%20Jersey%2008854&sensor=false

有什么建议?谢谢!

推荐答案

我不知道你的网址连接code方法是干什么的,但如果你是从像 URLEn codeR ,你永远不应该通过完整的网址,只是参数列表,你需要连接code转义特殊字符。

I'm not sure what your URL encode method is doing, but if you are using a method from the framework like URLEncoder, you should never pass the full URL, just the parameters list you need to encode to escape special characters.

编码完整的URL会逃跑百分之每一个字符,包括:// %3A%2F%2F 和所有附加斜线到%2F

Encoding the full URL will percent escape every character, including the :// into %3A%2F%2F and all additional slashes into %2F.

看看你的 goodUrl 字符串的值后,连接$ C C是$。

Take a look at the value of your goodUrl string after you encode it.

这篇关于主机名可能不Htt的presponse为Android执行空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 04:36