Request.Params understands [+] for a space - asp.net-mvc

I'm doing a request...something like this:
#Request.Params["id"].ToString()
the value of id is encripted and returns something like
ZK10ez/BJARTw GVLbIeUOp
instead of
ZK10ez/BJARTw+GVLbIeUOp <- this is what is passed in the URL
In other words, it's replacing my plus sign [+] with spaces [ ].
I could just do a replace, but I don't know if this will happen in the future with other letters.
Anyone with the same problem?

A + character in a URL represents a space character. This is an aspect of URL encoding.
Make sure that you properly URL encode any data before using it in a URL. You should not try and replicate URL encoding / decoding by doing your own string replacements.
You can use Url.Encode to encode your data prior to using it in a query string.

Related

Karate: Query Param values are getting encoded

I am using karate 0.6.1 version and facing issue with get request with queryparam.
Scenario Outline: Verify the response Data with account details when there are filter values are provided with wildcard
Given params { <paramName>: <paramValue> }
When method get
Then status 200
Examples:
| paramName | paramValue |
| Name | 'Volvo%' |
| Name | 'test data'|
in the request url with queryparam becomes like url?Name=Volvo%25
And url?Name=test+data
which is not correct, how should i resolve that.
It is actually not wrong,
Url encoding is required to differentiate between special characters in your data vs special characters that are reserved to construct the URL.
Reserved Characters URL Encoding:
: Separate protocol (http) from address encoded as %3B
/ Separate domain and directories encoded as %2F
# Separate anchors encoded as %23
? Separate query string encoded as %3F
& Separate query elements encoded as %24
# Separate username and password from domain encoded as %40
% Indicates an encoded character encoded as %25
+ Indicates a space encoded as %2B
<space> Not recommended in URLs encoded as %20 or +
so if you are going to pass any special characters as data via URL you need to % encode them to avoid conflicts.
In karate, if you want to avoid your URL getting encoded, don't construct your URL using path, params, param definitions.
Instead, build your entire URL as a string and pass it to url. like,
* url 'http://httpbin.org/get?Name=Stark'
You might get an exception if you are trying to pass any special
characters in this.
so consider encoding the URL if you are going to pass any special characters.

append space in URL in form of variable

I have an url say.
WWW.XYZ.COM
I have a varibale in bakend contains space in it. Then i want to add it with that url.
eg.www.xyz.com/variable or www.xyz.com/stack over
But url is not going to accept it. How can i do this?
A typical URL embed %20 in place of space.
That means your url www.xyz.com/stack overwill be treated as www.xyz.com/stack%20over. So, there can be a solution , write a function that will retrive data from backend as a %20 in every space. Then that will make an url. And try to make the pages appended as %20.
You have to use url encode like function to eliminate some characters (converting to other composite characters). Example of url encode in php
Say for Ex : this is your Stackoverflow URL
"stackoverflow.com/questions/51166674/append-space-in-url-in-form-of-variable"
Just Remove "-" in that.
Click Enter.
You Will See the same page with url
"stackoverflow.com/questions/51166674/append%20space%20in%20url%20in%20form%20of%20variable"
Just add %20 instead of space. I hope May be this is helpfull.
Thank you
Theory:
From HTML URL Encoding Reference
URLs can only be sent over the Internet using the ASCII character-set.
Since URLs often contain characters outside the ASCII set, the URL has to be converted into a valid ASCII format.
URL encoding replaces unsafe ASCII characters with a "%" followed by two hexadecimal digits.
URLs cannot contain spaces. URL encoding normally replaces a space with a plus (+) sign or with %20.
In other words, every character ('a', 'b', '', '_', ...) can be replace with its correspondant ASCII representation.
For example, the ASCII representation of space is %20.
Example: When you want to send the attribute "text" containing "Hello World" through a formular or URL, the web-server will process the input "text=Hello%20World" or, less frequent "text=Hello+World".
Your example: So, your URL www.xyz.com/stack over will be mostly represented as www.xyz.com/stack%20over
Reserved characther
= | ; | / | # | ? | : | space are reserved characters. RFC 1630

Swift: escape characters appear in json string

I'm constructing a JSON string by concatenating strings. To get the quotes correct for the web service (no quotes around numbers), I'm using escape characters. When I print the resulting string in Xcode, it looks fine.
{"number":999,"name":"new"}
But when I use Wireshark to capture what's going over the wire, I can see the escape characters in the string.
"{\"number\":999,\"name\":\"new\"}"
Here's the code that creates the string:
let jsonString:String = "{\"number\":" + num + ",\"name\":\"" + name + "\"}"
How can I create the string so the escape characters aren't there?
Thanks
The reason I couldn't send the JSON as a dictionary is that Swift dictionaries are unordered. In this case, the server is using MongoDB. I fixed the issue server side instead of trying to hack around it in the client.
Here's the reason: "Why does it happen: MongoDB uses a binary data format called BSON. In BSON, the order of keys always matters. Notice, in JSON an object is an unordered set of key/value pairs."
http://devblog.me/wtf-mongo
I'm fairly certain that the escape characters are being inserted by Wireshark in it's own output.

URL Escape in Uppercase

I have a requirement to escape a string with url information but also some special characters such as '<'.
Using cl_http_utility=>escape_url this translates to '%3c'. However due to our backend webserver, it is unable to recognize this as special character and takes the value literally. What it does recognize as special character is '%3C' (C is upper case). Also if one checks http://www.w3schools.com/tags/ref_urlencode.asp it shows the value with all caps as the proper encoding.
I guess my question is is there an alternative to cl_http_utility=>escape_url that does essentially the same thing except outputs the value in upper case?
Thanks.
Use the string function.
l_escaped = escape( val = l_unescaped
format = cl_abap_format=>e_url ).
Other possible formats are e_url_full, e_uri, e_uri_full, and a bunch of xml/json stuff too. The string function escape is documented pretty well, demo programs and all.

Is % percentage a valid url character

I am trying to put a url, something like the following urn:test.project:123, as part of the url.
Does it make sense to encode urn:test.project:123 into urn%3atest.project%3a123 and decode it back to urn:test.project:123 at the receiver end?
http://{domain}/abc/urn%3atest.project%3a123/Manifest
Yes, it's a valid character. It's the escape character for URLs in a similar way to how the ampersand & is the escape character for xml/html, and the backslash \ is the escape character for string literals in c-like languages. It's the (very important) character that allows you to specify (through an escape sequence) all the other characters that wouldn't be valid in a URL.
(And yes, it makes sense to encode such a string so it's a legal URL, and as #PaulPRO mentions, most frameworks will automatically decode it for you on the server-side.)
Yes, the %3a means that 3a is the HEX encoded value for ':'
If you put it in the url as %3a your server will most likely automatically decode it.

Resources