gpt4 book ai didi

java - makeHttpRequest 中的换行符

转载 作者:行者123 更新时间:2023-12-02 04:38:06 25 4
gpt4 key购买 nike

我收到java.lang.IllegalStateException:目标主机不得为空,或在参数中设置错误。进行 makeHttpRequest 时是新行字符,还是我在这里的路径不正确?代码:

        String url = "http://www.<myDomain>.co.za/insertTeamResultwithCode.php?Code="+code+
"&Section="+section+
"&Gender="+gender+
"&WinningTeam="+newResult.getWinningTeam()+
"&LosingTeam="+newResult.getLosingTeam()+
"&FixtureD="+newResult.getDate()+
"&FixtureT="+newResult.getTime()+
"&Venue="+newResult.getVenue()+
"&Court="+newResult.getCourt()+
"&Texts="+newResult.getText();

try
{
String encodedUrl = URLEncoder.encode(url, "UTF-8");

JSONParser jParser = new JSONParser();
JSONObject json = jParser.makeHttpRequest(encodedUrl, "GET", isSuccessfull);

try
{
boolean success = (json.getBoolean("isValid"));
DisplayToast(success);
}
catch (JSONException d)
{
d.printStackTrace();
}
}
catch (UnsupportedEncodingException e)
{
e.printStackTrace();
}

和 logcat 错误:

05-29 06:55:49.230: E/AndroidRuntime(25416): java.lang.IllegalStateException: Target host must not be null, or set in parameters. scheme=null, host=null, path=http://www.<myDomain>.co.za/insertTeamResultwithCode.php?Code=masjiensquash2015&Section=A&Gender=Men&WinningTeam=KZN&LosingTeam=WP&FixtureD=2015-05-29&FixtureT=09:00:00&Venue=Potch+CC&Court=1&Texts=mufasa+(KZN)+beat+scar+(WP)+3-0
05-29 06:55:49.230: E/AndroidRuntime(25416): (11-8,+11-6,+11-4)
05-29 06:55:49.230: E/AndroidRuntime(25416): optimus+(KZN)+beat+megatron+(WP)+3-0
05-29 06:55:49.230: E/AndroidRuntime(25416): (11-6,+11-3,+11-8)
05-29 06:55:49.230: E/AndroidRuntime(25416): Chuck+(KZN)+beat+Larry+(WP)+3-0
05-29 06:55:49.230: E/AndroidRuntime(25416): (11-5,+11-4,+11-4)
05-29 06:55:49.230: E/AndroidRuntime(25416): Tiger+(KZN)+beat+Rory+(WP)+3-0
05-29 06:55:49.230: E/AndroidRuntime(25416): (11-6,+11-3,+11-6)
05-29 06:55:49.230: E/AndroidRuntime(25416): Zandre+(KZN)+beat+Anzelle+(WP)+3-0
05-29 06:55:49.230: E/AndroidRuntime(25416): (11-5,+11-6,+11-2)

最佳答案

您不应该对完整的 URL 进行编码,因为它还会对主机部分进行编码,如下所示:

http%3A%2F%2Fwww.%3CmyDomain%3E.co.za%2FinsertTeamResultwithCode.php

这将失败,因为它无法解析此网址。

您应该仅对传递到此 URL 的参数进行编码。

关于java - makeHttpRequest 中的换行符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30521648/

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