Ameer
Ameer

Reputation: 2769

Illegal character in query android

java.lang.IllegalArgumentException: Illegal character in query at index 98: http://www.example.com&gmap=25.2600007|55.31000

I am trying to add the GoogleMap latitude and longitude to server, but I am getting Illegal character exception. I need to pass pipe symbol in between latitude and longitude

@Override
    protected void onPreExecute() {
        super.onPreExecute();


    }

    protected String doInBackground(String... args) {

        try {
            jsonResponseString = jsonParser.makeHttpRequestForAnnouncement(
                    "http:/example.com"&gmap=" + latlongString,
                    "POST");
        } catch (Exception e1) {

            e1.printStackTrace();
        }


        return null;

    }

    /**
     * After completing background task Dismiss the progress dialog
     * **/
    protected void onPostExecute(String file_url) {
        // dismiss the dialog once done


    }

and latlongString = String.valueOf(location.getLatitude() + "|" + String.valueOf(location.getLongitude()));

Upvotes: 0

Views: 198

Answers (2)

donfuxx
donfuxx

Reputation: 11323

In urls the pipe char | should be encoded as %7C

So your example url:

http://www.example.com&gmap=25.2600007|55.31000

should be:

http://www.example.com&gmap=25.2600007%7C55.31000

also you probably wanted & to be ? since it is the first url parameter.

==> Update: If you got this wrong encoded url from some api then you could fix it with doing a string replace, like for example:

String urlStr = "http://www.example.com&gmap=25.2600007|55.31000";
String fixedUrlStr = urlStr.replace("|", "%7C")

Upvotes: 1

Viral Patel
Viral Patel

Reputation: 33408

There is a single '/' after http: Needs to be '//'

Upvotes: 0

Related Questions