AM getting continuously the illegal character error in this url :
http://my.server.com/SelectPerson-0.1/nativeService/businessCardSave?company=Select Person&fullName=Rghh Dgivv&email=uday#uioperr.info&phoneNo=123456789&desiredPosition=Machine Operator&city=Dthhbv&state=AZ&zipcode=5369466¤tEmployer=Fgyevb¤tJobTitle=Dyhg &careerArea=Health and Personal Care&datasource=Android&location=Dthhbv AZ&did=J8C4N275YH1N9LGSZCG
Previously there was an extra & symbol , so I removed but still am getting same error.
Can anyone help me, in finding this illegal character in this url.
or anyone specify , the link for Httpost illegal characters
Thanks
# should be encoded (see the full list of characters that need encoding). For simplicity, you should just use URLEncoder.encode(yourString, "UTF-8"); for each of the values you're putting in the query string of that URL.
You probably need to replace the spaces in the url with %20
Related
I'm working on a solution where need to encode string into utf-8 format, this string nothing but device name that I'm reading using BluetoothAdapter.getDefaultAdapter().name.
For one of sampple I got a string like ABC-& and encoding this returned ABC-%EF%BC%86 instead of ABC-%26. It was weird until further debugging which helped to identify that there is difference between & and &. Second one is some other character which is failing to encoded as expected.
& and & both are different.
For encoding tried both URLEncoder.encode(input, "utf-8") and Uri.encode(input, "utf-8") but nothing worked.
This is just an example, there might be other character which may look like same as actual character but failed to encode. Now question are:
Why this difference, after all it is reading of some data from device using standard SDK API.
How can fix this be fixed. Find and replace with actual character could be a approach but scope is limited, there might be other unknown character.
Any suggestion around !!
One solution would be to define your allowed character scope. Then either replace or remove the characters that fall outside of this scope.
Given the following regex:
[a-zA-Z0-9 -+&#]
You could then either do:
input.replaceAll("[a-zA-Z0-9 -+&#]", "_");
...or if you don't care about possibly empty results:
input.replaceAll("[a-zA-Z0-9 -+&#]", "");
The first approach would give you a length-consistent representation of the original Bluetooth device name.
Either way, this approach has worked wonders for me and my colleagues. Hope this could be of any help 😊.
Using the below url I got an error:
java.lang.IllegalArgumentException: Illegal character in path at index 47: http://safetracker-threetinker.rhcloud.com/api/{userid}/locations?lat={latitude}&lng={longitude}.
URL:
URL=http://safetracker-threetinker.rhcloud.com/api/{userid}/locations?lat={latitude}&lng={longitude}
how to solve the error. I don't have good knowledge in URL encoding. please help me to find the solution.
The problem is actually it is looking for long/integer value and you are passing a { just put a $ so that it will be replaced by the actual value pointed by the variable
http://safetracker-threetinker.rhcloud.com/api/1/locations?lat=5&lng=5
your Address is like this
URL=http://safetracker-threetinker.rhcloud.com/api/{userid}/locations?lat={latitude}&lng={longitude}
it should be like this
URL=http://safetracker-threetinker.rhcloud.com/api/${userid}/locations?lat=${latitude}&lng={longitude}
We can not use some special characters in URL, so we have to replace these special characters with its encoded form.
Replace your URL with following URL
URL=http://safetracker-threetinker.rhcloud.com/api/%7Buserid%7D/locations?lat=%7Blatitude%7D&lng=%7Blongitude%7D
May this help you.
URLEncoder should be the way to go. You only need to keep in mind to encode only the individual query string parameter name and/or value, not the entire URL, for sure not the query string parameter separator character & nor the parameter name-value separator character =.
String q = "replace_with user_id/locations?lat=replace with latitude&lng=replace with longitude";
String url = "http://safetracker-threetinker.rhcloud.com/api/=" + URLEncoder.encode(q, "UTF-8");
i got a problem which i tried hard to solve with searching with google because will be a simple solution.
I want to open the following url:
http://<<IP>>/query.html?sql="select * from ADAnreden"
To do this, i write this url in a string to open it with HttpGet...
String url = "http://"+ip+"/query.html?sql=\"select * from ADAnreden\"";
So i escaped the " infront of select and after ADAnreden. But the problem is that the following error is comming up:
Illegal character in query at index 36.
This is the equals sign. So how can i escape the = ? The backslash is not working.
Thanks for help
The issue is the escaping for the URL, not for Java. Spaces are not valid in URLs. See this answer for more about URL encoding in Android.
you must encode the query before using it as URL, see URLEncoder.encode(query);
I am getting some strings from json. My string contains special characters like "æ" from Næstved an many more like "ø" from køkken. But When I set Text these strings to ant textview, I get my strings printed in unusual way.
Example: For køkken I get kø ;kken.
I think I need to encode or decode my string somewhere but where I don,t know.
Please help.
Thanks in advance
The displayed version of your string represents an HTML encoded entity. You might want to verify that it is not coming in this way in your JSON data, but in any case, to decode it you can use the StringEscapeUtils.unescapeHtml4 method from Apache Commons Lang:
final String escaped = "køkken";
System.out.println(StringEscapeUtils.unescapeHtml4(escaped));
Output:
køkken
Did you check out the Latin Coding for your characters? I know the Ash character can be coded with æ and will show up æ in the browser.
Here is the a list of codes
Hope this helps!
I'm reading a file into a jsonobject from my assets folder. The file contains json string.
Some of the strings contain "'" (apsotrophe) character. The problem is that the textview shows "?" in place of these apostrophes. Why is this happening. When I print the json string to logcat using mJsonObject.toString(), it shows proper character.
How can I get rid of this "?" and show actual character?
The Apostrophe probably isn't a simple ' apostrophe, but some advanced typographic apostrophe that is missing in your font and/or gets mangled during charset conversions. Preferably, replace the typographic apostrophes with plain apostrophes in the JSON file.
If you don't want to do so, escape them using the \u escape. This makes sure that the correct character ends up in the JsonObject. If you still get the question mark, make sure your font supports the character and that you don't break it in other charset conversions.
If you cannot use \u escapes for some reason, make sure you read the file with the correct charset.