2013-05-21 38 views
0

當我嘗試向具有特殊字符(字符'å')的服務器發出HTTP請求時,我總是收到上述錯誤(標題) 。我曾嘗試致電:繼續收到「目標主機不能爲空或在參數中設置」

_login = URLEncoder.encode(_login, "utf-8"); 

但我仍然得到例外。如果我嘗試更改網址,它可以正常工作。似乎它發生的任何URL我嘗試,如果它有特殊字符。例如http://www.ål.no

任何人都知道解決方法?一種方法當然可以使用IP地址。但我寧願避免這種情況。

感謝您的幫助!

一些源代碼:

private String _login =  "http://www.ål.no"; 

    HttpClient httpclient = new DefaultHttpClient(); 

    try { 
     _login = URLEncoder.encode(_login, "utf-8"); 
    } catch (UnsupportedEncodingException e1) { 
     // TODO Auto-generated catch block 
     e1.printStackTrace(); 
    } 

    HttpPost httppost = new HttpPost(_login); 

    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); 

    //nameValuePairs.add(new BasicNameValuePair("Mail", this.Email)); 
    //nameValuePairs.add(new BasicNameValuePair("Password", this.Password)); 


    try 
    { 
     httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 

     BasicHttpResponse response = null; 

     try 
     { 
      response = (BasicHttpResponse) httpclient.execute(httppost); 
     } 
     catch (ClientProtocolException e) 
     { 
      System.out.println("BasicHttpResponse"); 
      e.printStackTrace(); 
     } 
} 

編輯:找到一個變通。使用Firebug挖深一點。根據Firebug,服務器在通信時有另一個名字(據我所知)。該名稱不包含任何特殊字符,並且我成功設法使用我的應用程序與服務器通信。感謝所有幫助! :)

+0

不知道這是否是同樣的問題,但是看看這個問題:http://stackoverflow.com/questions/1133424/what -are最有效的字符,也就是說,可以出現向上-IN-A-URL主機 –

回答

相關問題