gpt4 book ai didi

java - 从用于 http 连接的字符串中删除空格

转载 作者:行者123 更新时间:2023-11-29 08:03:06 24 4
gpt4 key购买 nike

我正在尝试发送一个查询 url

String url = String.format(
"http://xxxxx/xxx/xxx&message=%s",myEditBox.getText.toString());
// Create a new HttpClient and Post Header
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
httpclient.getCookieStore().addCookie(cooki);
try {
ResponseHandler<String> responseHandler = new BasicResponseHandler();
httpclient.getParams().setParameter("http.connection-manager.timeout", 15000);
String response = httpclient.execute(httppost, responseHandler);

给我错误,查询时出现非法字符。那可能是 white space。如何处理这个问题?

最好的问候

最佳答案

您需要对您的网址进行编码。

String query = URLEncoder.encode(myEditBox.getText.toString(), "utf-8");
String url = "http://stackoverflow.com/search?q=" + query;

关于java - 从用于 http 连接的字符串中删除空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13173295/

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