簡體   English   中英

Java Android非法參數異常

[英]Java Android Illegal Argument exception

我正在執行以下代碼:

HttpClient httpclient = new DefaultHttpClient();

HttpResponse response = httpclient.execute(new HttpGet("(...)&avatarUrl={(...)}&socialId=1&sexo=m&username="));

我的問題是我從avatarUrl單詞的字母l處收到了一個illegalArgumentExceptionavatarUrl ,我不明白為什么。

非常感謝您的幫助。

除了問題? 奧德&在你的代碼中,有簡潔的方式來傳遞參數:

HttpClient httpclient = new DefaultHttpClient();
HttpGet request = new HttpGet(url);
BasicHttpParams params = new BasicHttpParams();

params.setParameter("avatarUrl","...")
      .setParameter("socialId","...")
      .setParameter("sexo","...")
      .setParameter("username","...");

request.setParams(params);

HttpResponse response = httpclient.execute(request);

(未經測試,但應該可以工作)

注意:由於一些誤解,我對原始答案進行了大量編輯。

查看HttpGet源代碼 ,此異常意味着URL無效:

  1. 第一個查詢字符串參數之前應帶有?
  2. {} 對網址不是有效的字符 ,應將其轉義

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM