HandleSpecialURL & decodeURLComponent

First time building a web app:
I have trouble with my Web App communicating to a desktop app via HTTPSocket.post & HandleSpecialURL.

My desktop application populates a dictionary and uses setFormData on the socket before calling the “POST” function.
My web app receives the post fine and using request.entity it re-assembles the dictionary. The trouble I’m facing is that any spaces within the values are replaced with “+”.

I’ve tried decodeURLComponent on the entire request.entity and just on the extracted value, but it doesn’t remove the “+”.

Here’s the latest code I’ve tried.

[code] Try
Dim values() as string = split( decodeURLComponent( request.Entity ), “&” )
Dim n,l as integer

  n = ubound( values )
  for l=0 to n
    arguments.value( nthfield( values( l ), "=", 1 ) ) = nthfield( values( l ), "=", 2 )
    print nthfield( values( l ), "=", 1 ) + ": " +  nthfield( values( l ), "=", 2 )
  next
End try[/code]

Example “Sam Rowlands”, always returns “Sam+Rowlands”.

Am I doing this wrong or am I missing something?

I could use code to replace the “+” with a space, but I’m concerned that there may be other surprises waiting for me down the road! Ultimately, this web app will communicate with a third party, not me, so I don’t want it to fail for them.

GET/POST is encoded as “application/x-www-form-urlencoded” and that uses “+” as Space instead of %20.
Both + and %20 should be considered safe to use though :slight_smile:

Ha, just realized my post might now have been much help, sorry.

Thanks Albin,
Just tried that and it makes matters worse, my name is now “Sam%2520Rowlands” and decodeURL still doesn’t resolve it back to “Sam Rowlands”.

Maybe this is just a quirk of the HTTPSocket, and it’ll work fine when the vendor starts using it… but it’s making me nervous!

Sorry - for some reason, I though you said encodeURLComponent the data when stuffing it into the dictionary, which doesn’t help!

I did say that but realized it might not work so I edited my post.
Is there some way to test it with the vendor? If they have things set up correctly I’d guess it will work but I can see why you’re nervous! :wink:

Maybe someone else have more knowledge on this here than I do :slight_smile:

Sam,

I think this is a limitation of decodeURLComponent in Xojo. It seems that it only recognizes the %20 as the space character and not the “+” (which is only used in arguments in query strings like this). I think it would be safe for you just to manually replace the “+” with a space. I doubt you will run into any other issues.

This could be considered a bug, or a feature request I guess :wink:

Not yet, I was hoping that their engineers would contact me today, but so far haven’t… I’m still waiting on some other information before I also make this live on a web host (right now it’s all running from the same Mac).

Thanks John, I’ll use the replaceAll function for the moment, perhaps I should convert the “+” sign into “%20” and let decodeURLComponent process it, so I don’t screw up something else?

Hopefully someone from Xojo will pick this up in their morning and let me know if they consider it a bug or a feature request and I’ll then log it.

Thanks all for your help - Up and at-them!

Here is something that works - I just tried it, give it a try and let me know what you get:

 Try
      Dim values() as string = split( decodeURLComponent( request.Entity ), "&" )
      Dim n,l as integer
      dim thisValue as string 
      
      n = ubound( values )
      for l=0 to n
        thisValue = nthfield( values( l ), "=", 1 )
        arguments.value(thisValue) = request.GetParameter(thisValue)
        print thisValue + ": " +  request.GetParameter(thisValue)
      next
    End try

WebRequest.GetParameter seems to properly form-DEcode the parameters.

Since you control both ends, you could send the body of the Post as xml or json. That would bypass any encode/decode issues.

For what it’s worth, we use CURLMBS to communicate from desktop apps to and from web apps. We generally use JSON to format the data. The decision to use CURL was made many years ago and lost to the annals of history…

Thanks Guys, I’ll give John’s tip a try first.

At the moment I do, but once it’s complete it will be third parties who’ll be using the service, which is why I want to make sure that the web app is doing everything by the book.

Thanks Bob, I’ve now received their documentation on WebHooks, so I’ll check it over.