WebRequest.Header stripping characters

I am passing some data through urlconnection to web app and in the request header the data is getting stripped

urlcon.RequestHeader(“SQL”) = “select name, age from person where name like ‘%chris%’ and age = 2”

I am getting the result in web handleURL in webRequest Header as below. It stripped the space near the comma and stripped the percentage sign (%)

select name,age from person where name like ''ris and age = 2

Any idea how this could be avaoided.

Don’t put something like that in a header. They’re not meant for that.


Then how do i pass similar data to web app. Is there any other method?

The data should be sent in the body of the request.

How to do you set the body. Is it using SetRequestContent. If not any example.

Yes. SetRequestContent will work. For text like this, the type will be “text/plain”

That said, make sure you’re authenticating requests. Allowing clients to send raw requests is a good way to have a malicious person download or delete your data.

1 Like

Thanks for the suggestion

According to the RFC spec, all ascii characters are technically allowed in HTTP headers, however there seems to be some wide variability as to how these are received and processed by different server implementations (including Xojo it appears).

Greg’s suggestion of putting it in the body is the most straightforward and logical approach to resolve this.
If you do end up in a situation where you need the body for something else and have to use headers then my recommendation would be to use Base64 encoding if you think the value contains binary or non alphanumeric data. Then you can base64decode at the server end and be sure you’ll get accurate data

Good idea. Thanks

There are special characters in a url request, such as ? and %. If you wish to use those characters, you must use EncodeUrlComponent to make them compliant with the spec.