简体   繁体   中英

Newline character in makeHttpRequest

I am getting a java.lang.IllegalStateException: Target host must not be null, or set in parameters error. Is new line characters when making doing makeHttpRequest, or am I on the incorrect path here? Code:

        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();
        }

And logcat error:

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)

You should not do encoding of complete URL as it will also encode host part like this :

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

This will fail, since it is not able to parse this url.

You should encode only parameters passed to this URL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM