Skip to content Skip to sidebar Skip to footer

How Can I Send A Post Request With Spaces?

I'm trying to send input from an edittext to PHP. If I send in something with no spaces it works ok, but crashes with spaces and says this: illegal character ...which refers to

Solution 1:

A standard browser takes any spaces entered into the address bar and replaces them with %20; HTML's space character.

HTTP does not do this, the browser does, meaning that you have two options:

  1. Create a function to take in a string and replace all spaces with %20;
  2. Manually replace spaces with %20

For example:

String sessionCouse ="\'Software Development With Spaces\'";

should actually be

String sessionCouse = "\'Software%20Development%20With%20Spaces\'";

Solution 2:

When communicating with a backend server programmatically you should use URL encode to encode you input properly:

String fullURL ="http://example.com/android/project_group_notes_details.php?course=\'"+URLEncoder.encode(sessionCouse, "UTF-8") +"\'";

Post a Comment for "How Can I Send A Post Request With Spaces?"