is there any way to pass string contains '+' via the Querystring - asp.net

I need to pass '+' via the QueryString.
some special character can be passed by using 'Encode' .. but '+'
I know the one solution, If I replace '+' with other character.
But it's not the perfect solution.
[edited]
well I used escape() javascript function to encode.
escape function can't encode + . is the another function to encode on javascript?

Rather than handling on a case by case basis, with Javascript you can encode all data you pass via query string with encodeURIComponent
<script>
var data = ")(#&^$#*&^#!(!*++=";
var encodedData = encodeURIComponent(data);
alert(encodedData);
</script>

Use %2b to pass the + character.

The space character is usually passed as %20.
The same way, the plus sign can be passed as %2B

In ASCII, the hex code for + is 2B, so you should be able to just use %2B instead of +.
http://www.google.com/search?q=c%2B%2B+java

Related

How to pass exact string as parameter in robot framework

I have the follow test case :
Some function
    Given some condition
    When I go to "\\path\to\folder"
    Then I don't know
I want to use exact: **"\\\\path\to\folder"** as string in my keyword argument
When I use above string, I'm getting escaped value.
I tried to use:
r"\\path\to\folder"
'\\path\to\folder'
Thank you.
The backslash is an escape character in robot, so to send a backslash you must escape the backslash.
When I go to \\\\path\\to\\folder
One solution is to escape it once again:
When I go to \\\\path\\to\\folder
Or you can use:
When I go to ${/}${/}path${/}to${/}folder
which will pass \\path\to\folder.
Another way to do it is to use a python raw string and just Evaluate it:
${my_string} Evaluate r"a\\b"
Log To Console ${my_string}

ognl array values as GET parameters

I have an application using struts2-ognl. I have an array of strings and it gets populated by GET parameters in the request. Like the following example
http://localhost:8080/myapp/myAction.action?myArray[1]=value1&myArray[2]=value2 etc etc
Is there any way to instruct ognl that for arrays I don't want to use "[" or "]" but another set of characters ( let;s say for example "(" and ")" so the url could work like:
http://localhost:8080/myapp/myAction.action?myArray(1)=value1&myArray(2)=value2 etc etc
I'm asking this because "[" and "]" are url reserved characters. I have tried to urlEncode them but then ognl ignores those parameters.

Flex + character getting replaced by blank when passed as application param

I am passing a string param into flex application as FlashVars
The param sometime contains special characters, everything shows fine except + sign which gets replaced by blank when it reaches flex.
Here is the scenario for eg.
I have a local variable in JS that gets some values and for this example it can be taken as following
<script language="JavaScript" type="text/javascript">
var testVar = "some_test_string_that_contains_+_character";
</script>
Then to my Flex object AC_FL_RunContent I pass "FlashVars","test="+testVar
In the flex code on Init of application I have written
var testValue:String = application.parameters["testVar"].toString();
Alert.show(testValue);
Now this shows fine except the + character gets replaced by blank. It doesnt happens with other characters like /,#$-_ but the + character.
Any help regarding this will be greatly appreciated.
From Adobe's docs:
About flashVars properties encoding
The values of the flashVars properties
must be URL encoded. The format of the
string is a set of name-value pairs
separated by an ampersand (&). You can
escape special and nonprintable
characters with a percent symbol (%)
followed by a two-digit hexadecimal
value. You can represent a single
blank space using the plus sign (+).
Looking further down at one of the comments from matthew horn, it looks like you can use %2B to pass the + character.

HttpServerUtility.UrlPathEncode vs HttpServerUtility.UrlEncode

What's the difference between HttpServerUtility.UrlPathEncode and HttpServerUtility.UrlEncode? And when should I choose one over the other?
UrlEncode is useful for query string values (so to the left or especially, right, of each =).
In this url, foo, fooval, bar, and barval should EACH be UrlEncode'd separately:
http://www.example.com/whatever?foo=fooval&bar=barval
UrlEncode encodes everything, such as ?, &, =, and /, accented or other non-ASCII characters, etc, into %-style encoding, except space which it encodes as a +. This is form-style encoding, and is best for something you intend to put in the querystring (or maybe between two slashes in a url) as a parameter without it getting all jiggy with the url's control characters (like &). Otherwise an unfortunately placed & or = in a user's form input or db value value could break things.
EDIT: Uri.EscapeDataString is a very close match to UrlEncode, and may be preferable, though I don't know the exact differences.
UrlPathEncode is useful for the rest of the query string, it affects everything to the left of the ?.
In this url, the entire url (from http to barval) should be run through UrlPathEncode.
http://www.example.com/whatever?foo=fooval&bar=barval
UrlPathEncode does NOT encode ?, &, =, or /. It DOES, however, like UrlEncode, encode accented/non-ASCII characters with % notation, and space also becomes %20. This is useful to make sure the url is valid, since spaces and accented characters are not. It won't touch your querystring (everything to the right of ?), so you have to encode that with UrlEncode, above.
Update: as of 4.5, per MSDN reference, Microsoft recommends to only use UrlEncode. Also, the information previously listed in MSDN does not fully describe behavior of the two methods - see comments.
The difference is all in the space escaping - UrlEncode escapes them into + sign, UrlPathEncode escapes into %20. + and %20 are only equivalent if they are part of QueryString portion per W3C. So you can't escape whole URL using + sign, only querystring portion. Bottom line is that UrlPathEncode is always better imho
You can encode a URL using with the UrlEncode() method or the UrlPathEncode() method. However, the methods return different results. The UrlEncode() method converts each space character to a plus character (+). The UrlPathEncode() method converts each space character into the string "%20", which represents a space in hexadecimal notation. Use the UrlPathEncode() method when you encode the path portion of a URL in order to guarantee a consistent decoded URL, regardless of which platform or browser performs the decoding.
http://msdn.microsoft.com/en-us/library/4fkewx0t.aspx
To explain it as simply as possible:
HttpUtility.UrlPathEncode("http://www.foo.com/a b/?eggs=ham&bacon=1")
becomes
http://www.foo.com/a%20b/?eggs=ham&bacon=1
and
HttpUtility.UrlEncode("http://www.foo.com/a b/?eggs=ham&bacon=1")
becomes
http%3a%2f%2fwww.foo.com%2fa+b%2f%3feggs%3dham%26bacon%3d1

Request.QueryString giving me space instead of + sign

If I have a URL value http://Localhost/default.aspx?ts=/+m2dAZZA3DaavaaupUXkZL83n7TwmCVm
Request.QueryString[ts] is giving me
/ m2dAZZA3DaavaaupUXkZL83n7TwmCVm
How to ensure that I get all the value from the Querystring
is there an encoding or something?
Use: http://Localhost/default.aspx?ts=/%2Bm2dAZZA3DaavaaupUXkZL83n7TwmCVm instead.
Special characters in URLs are formatted as %XX where XX is the hex representation of the ASCII value. In this case, the + sign is 43, thus our URL value will be %2B.
whatever code that generates your URL needs to escape it properly. Use HttpUtility.UrlEncode() server-side or ecodeURIComponent() client-side
try using Server.urlencode and Server.urldecode or use %2B instead of +
Here is list of encodings to use for such characters.
Do not use a + in the parameter value. Instead, choose another character that is URL friendly and will not otherwise be used. Replace the + before adding the value to the URL. Then replace it with a + when the value is retrieved.

Resources