How to format string parammeter?

ThePuiu

Active Member
Licensed User
Longtime User
Hi!
I try to send to an aspx page the following string as parameter:
HTML:
1%2013-02-12 00:00:00%1900-01-01 13:48:22%Mlaştini turboase de tranziţie şi turbării mişcătoare%Bolovănișuri%Histosoluri%N%12%alte%12345%pc%pe%as%buna%am%ma%in
but I get the following error message:

httputilsservice_processnexttask (java line: 222)
java.lang.IllegalArgumentException: Illegal character in query at index 59: http://android.xxxxx.ro/upload.aspx?observatie=1 13-02-12 00:00:00%1900-01-01 13:48:22%Mlaştini turboase de tranziţie şi turbării mişcătoare%Bolovănișuri%Histosoluri%N%12%alte%12345%pc%pe%as%buna%am%ma%in

If I try to change spaces with & I recieve error:

Caused by: java.lang.IllegalArgumentException: Invalid % sequence: %Ml in query at index 88: http://android.xxxxx.ro/upload.aspx...istosoluri%N%alte345%pc%pe%as%buna%am%ma%in

So, how to format the string to avoid these errors?
TY!
 

sirjo66

Well-Known Member
Licensed User
Longtime User
You need to "url-encode" your command string, because it contains characters that are not allowed in url string, because are special characters.

These characters are space and "%".

So, you need first to replace "%" char with "%25" (without "),
and then change space with "%20"
(%25 is the hex code of %, %20 is the hex code of space, see an ASCII table at Ascii Table - ASCII character codes and html, octal, hex and decimal chart conversion )

If you receive errors again, I think you need to change also other special characters, for example "ş", "ţ", "ă", and so on.....

Sergio
 
Upvote 0

ThePuiu

Active Member
Licensed User
Longtime User
I tried to use EncodeUrl, but I ran into another problem: the string passed contains points (dots) that remain unaltered. What symbol can replace them?

Later Edit:
I replaced in the string points (dots) with ^ char, then I applied EncodeUrl. The result is a string like:
http://android.xxxxx.ro/uploadspeci...fo~41^5644~23^7643~padure~1970-01-01+02:00:00

When I send this string, my server response: 404 - File or directory not found. (even the page uploadspecii.aspx exists)
 
Last edited:
Upvote 0

sirjo66

Well-Known Member
Licensed User
Longtime User
I tried to use EncodeUrl, but I ran into another problem: the string passed contains points (dots) that remain unaltered. What symbol can replace them?

Later Edit:
I replaced in the string points (dots) with ^ char, then I applied EncodeUrl. The result is a string like:
http://android.xxxxx.ro/uploadspeci...fo~41^5644~23^7643~padure~1970-01-01+02:00:00

When I send this string, my server response: 404 - File or directory not found. (even the page uploadspecii.aspx exists)

If you search dot in ASCII table, you can find that is hex code 2E, so you need to change dots with "%2E"

Sergio

P.S.: where are you from ??
 
Last edited:
Upvote 0

ThePuiu

Active Member
Licensed User
Longtime User
I think I'll go crazy... whatever I do is not good ... same damn error:
<h2>404 - File or directory not found.</h2>
File is in right place, and if you don't provide any parameter gives an error message.

This is code:
HTML:
....
REZ = Cursor1.GetInt("ID_USER") & "~" & DateTime.Date(Cursor1.GetLong("DATA")) & " 00:00:00" _
         & "~1900-01-01 " & DateTime.Time(Cursor1.GetLong("ORA")) & "~" & Cursor1.GetString("TIP_HABITAT") _
         & "~" & Cursor1.GetString("SUBSTRAT") & "~" & Cursor1.GetString("SOL") & "~" & Cursor1.GetString("EXPOZITIE") & "~" & Cursor1.GetString("PANTA") _
         & "~" & Cursor1.GetString("ALTELE") & "~" & Cursor1.GetString("SUPRAFATA") & "~" & Cursor1.GetString("STRUCTURA1") & "~" & Cursor1.GetString("STRUCTURA2") _
         & "~" & Cursor1.GetString("STRUCTURA3") & "~" & Cursor1.GetString("STARE_CONSERVARE") & "~" & Cursor1.GetString("AMENINTARI") _
         & "~" & Cursor1.GetString("MASURI") & "~" & Cursor1.GetString("OBSERVATII") _
         & "~" & DateTime.Date(Cursor1.GetLong("MOMENT")) & " " & DateTime.Time(Cursor1.GetLong("MOMENT"))
         REZ = ModificaSpatiu(REZ)
         REZ = su.EncodeUrl(REZ,"UTF8") 
'---------------------------------------------------------------
Sub ModificaSpatiu(STR As String)
STR = STR.Replace(" ","%20")
STR = STR.Replace(".","%2E")
Return STR
End Sub

......
URL = "http://android.mmare.ro/uploadspecii.aspx?observatie=" & REZ

Finally, URL has the value:
http://android.mmare.ro/uploadspeci...%2E5434~23%2E7654~local~1970-01-01%2002:00:00


Pls help me!!!

(I'm from Romania)
 
Upvote 0

sirjo66

Well-Known Member
Licensed User
Longtime User
I don't understand what you need to do.

You need to download a file ??

First you need to try with a PC and a browser for to see how to create you URL and test it if works.
Then you can re-create it with Android

If I click on your link, the system also say to me "error", so the problem isn't on B4A source code, you need first to find the correct command.

Sergio
 
Upvote 0

ThePuiu

Active Member
Licensed User
Longtime User
I try to send data from my tablet to a SQL Server. That string is a sequence of fields of the table to be sent to the server.
If the aspx's querystring is initialized with the string generated by Android, everything is ok. The error only occurs if the string generated by Android is sent to the aspx page as input parameter.

My guess is: that combination of character string mislead browser and makes it look for a file that does not exist on the server. This explains that 404 error...
 
Upvote 0

ThePuiu

Active Member
Licensed User
Longtime User
Yes, my code is based on that example...and my Android application uses this method in several places where it works perfectly...
 
Upvote 0
Top