gpt4 book ai didi

android - java.lang.illegalargumentexception url 中的非法字符

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:43:43 24 4
gpt4 key购买 nike

我想请求网络服务
我的参数是这样的

urlString = http://ip/autodownload/andro.php?key=apps.apk|2|bla.bla.bla

public void getRequest(String Url) {
Toast.makeText(this, "Tambah Data " + Url + " ", Toast.LENGTH_SHORT).show();
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(urlString);
try {
System.out.println("tes");
HttpResponse response = client.execute(request);
Toast.makeText(this,request(response),Toast.LENGTH_SHORT).show();
String res = EntityUtils.toString(response.getEntity());
System.out.println(res);
Update(res);
} catch (Exception ex) {
Toast.makeText(this, "Gagal Konek Server !", Toast.LENGTH_SHORT).show();
}
}

如果我在浏览器中运行没问题,但是当我在android中运行时就出现这样的错误

10-25 10:24:49.862: ERROR/AndroidRuntime(14602): FATAL EXCEPTION: main
10-25 10:24:49.862: ERROR/AndroidRuntime(14602): java.lang.IllegalArgumentException: Illegal character in query at index 67: http://10.234.152.120/autodownload/andro.php?key=DeliverReceipt.apk|2|com.sat.deliver
10-25 10:24:49.862: ERROR/AndroidRuntime(14602): at java.net.URI.create(URI.java:970)
10-25 10:24:49.862: ERROR/AndroidRuntime(14602): at org.apache.http.client.methods.HttpGet.<init>(HttpGet.java:75)
10-25 10:24:49.862: ERROR/AndroidRuntime(14602): at com.sat.deliver.MenuUtama.getRequest(MenuUtama.java:140)
10-25 10:24:49.862: ERROR/AndroidRuntime(14602): at com.sat.deliver.MenuUtama.requestParam(MenuUtama.java:118)
10-25 10:24:49.862: ERROR/AndroidRuntime(14602): at com.sat.deliver.MenuUtama.onClick(MenuUtama.java:355)
10-25 10:24:49.862: ERROR/AndroidRuntime(14602): at android.view.View.performClick(View.java:2408)
10-25 10:24:49.862: ERROR/AndroidRuntime(14602): at android.view.View$PerformClick.run(View.java:8816)
10-25 10:24:49.862: ERROR/AndroidRuntime(14602): at android.os.Handler.handleCallback(Handler.java:587)
10-25 10:24:49.862: ERROR/AndroidRuntime(14602): at android.os.Handler.dispatchMessage(Handler.java:92)
10-25 10:24:49.862: ERROR/AndroidRuntime(14602): at android.os.Looper.loop(Looper.java:123)
10-25 10:24:49.862: ERROR/AndroidRuntime(14602): at android.app.ActivityThread.main(ActivityThread.java:4627)
10-25 10:24:49.862: ERROR/AndroidRuntime(14602): at java.lang.reflect.Method.invokeNative(Native Method)
10-25 10:24:49.862: ERROR/AndroidRuntime(14602): at java.lang.reflect.Method.invoke(Method.java:521)
10-25 10:24:49.862: ERROR/AndroidRuntime(14602): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-25 10:24:49.862: ERROR/AndroidRuntime(14602): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-25 10:24:49.862: ERROR/AndroidRuntime(14602): at dalvik.system.NativeStart.main(Native Method)

我已经尝试使用 Urlencoding 和替换字符,但它不起作用
我该怎么办?谢谢
*已解决
我在 urlString 中替换字符,例如:

urlString+="?key="+appName.trim().replace(".", "%2E")+"|2|".trim().replace("|", "%7C")+packageName.trim().replace(".", "%2E");

它工作正常:)

最佳答案

尝试编码你的 URL

String link="http://example.php?string1="+URLEncoder.encode(string1)+"&string2="+URLEncoder
.encode(string2)+"&string3="+URLEncoder.encode(string3)+"&string4="+URLEncoder.encode(string4)+"";

关于android - java.lang.illegalargumentexception url 中的非法字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13061144/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com