天道酬勤,学无止境

Plus sign in query string

Question

I have a webapp created using C# and asp.net. I placed a parameter value in the querystring with a plus(+) sign. But the plus sign disappear.

How can I include the plus sign(+) in the query string without disappearing?

Please advise.

Thanks.

Edit: added code with UrlEncode

string str = Server.UrlEncode(Requery.QueryString["new"]);
Answer1

+ sign has a semantic meaning in the query string. It is used to represent a space. Another character that has semantic importance in the query string is & which is used to separate the various var=value pairs in the query string.

Most server side scripts would decode the query parameters before using them, so that a + gets properly converted to a space. Now, if you want a literal + to be present in the query string, you need to specify %2B instead.

+ sign in the query string is URL-decoded to a space. %2B in the query string is URL-decoded to a + sign.

See the difference between

http://www.google.com/search?q=foo+bar

and

http://www.google.com/search?q=foo%2Bbar

In the above examples, Google's server script is URL-decoding the query parameters and then using them to do the search.

URL-encoding is nothing but % sign followed by the hex-code of the special character. For example, we know that the hex code of A is 0x41 (decimal: 65). Try this:

http://www.google.com/search?q=%41

Hope this makes URL-encoding clear.

So, if you want the + sign to be preserved when a JavaScript is fetching a URL with + signs in its query parameters and a server side script would process the query parameters after URL-decoding it, you should URL-encode the query parameters in the URL before using issuing the HTTP get request so that all + signs are converted to %2B's when the request reaches the server side script. Now when the server side script URL-decodes the query string, all %2B's gets converted back to + signs which is what you want.

See Encode URL in JavaScript? to learn how to URL-encode the parameters using JavaScript. Short answer from the discussion there:

var encodedURL = "http://example.com/foo.php?var=" + encodeURIComponent(param);
Answer2

You should URLEncode your query string values to make sure any special characters are not lost.

Answer3

Look at HTML URL Encoding Reference

You need to Encode the + sign - It's value should be %2B

Answer4

I alter my previous statement so no one gets confused!

Create your url using the Server.UrlEncode. e.g.

string myUrl = "http://myurl?param1="  + Server.UrlEncode("my+param+1");
Answer5

Other simple way is, Request.Url.ToString().Substring(Request.Url.ToString().IndexOf("=") + 1) assuming that my URL is, http://localhost/MyApp/Activate.aspx?ActivationCode=cHbtqH9P2dDZkx/mYUgFFo7nrNqSFgqdPisAzzu5/nwlEYDOHI+CQw==

Answer6

before send you parameter, you need check if the parameter contains plus sign, if have you need replace to one flag, for example: the parameter is: klasjdlkasd+djid3223 can you replace: klasjdlkasdFLAGdjid3223

and when you go convert, you need replace angain

klasjdlkasd+djid3223

Answer7

For the solution, I have applied:

Step 1:Use Server.UrlEncode method for encoding the URL parameter. Response.Redirect("YourURL?parameter=Server.UrlEncode(parameterValue.ToString().Trim()");

step 2: on another side, you get a string with a plus(+) sign. var parameter = Request.QueryString["parameterValue"].ToString().Trim();

This is the result: %2beH8 --> +eH8

Answer8

Try this, it works for me:

Request.QueryString["new"].Trim();
Answer9

The solution is to ALWAYS include .Replace(" ", "+") when you request querystring

string s = Request.QueryString["id"].Trim().Replace(" ", "+");

source: http://www.webmasterworld.com/forum47/3238.htm

Answer10

Add this line in Decrypt Funcation:

strText = strText.Replace(" ", "+");

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.

相关推荐
  • In a URL, should spaces be encoded using %20 or +? [duplicate]
    Question This question already has answers here: URL encoding the space character: + or %20? (4 answers) Closed 4 years ago. In a URL, should I encode the spaces using %20 or +? For example, in the following example, which one is correct? www.mydomain.com?type=xbox%20360 www.mydomain.com?type=xbox+360 Our company is leaning to the former, but using the Java method URLEncoder.encode(String, String) with "xbox 360" (and "UTF-8") returns the latter. So, what's the difference? Answer1 Form data (for GET or POST) is usually encoded as application/x-www-form-urlencoded: this specifies + for spaces
  • python artificial intelligence dialogue
    import urllib.parse import hashlib import time import random import string import requests import sys import readline def curl_md5(src): m = hashlib.md5(src.encode('UTF-8')) # Convert all characters of the obtained MD5 value to uppercase return m.hexdigest().upper() """ get_req_sign: Calculate the request signature parameter description based on the interface request parameters and the application key -pa: interface request parameters -apk: Application key to return data -Signature result """ def get_req_sign(pa, apk): # 1.字典升序排序 pa_list = list(pa.items()) pa_list.sort() # 2.拼按URL键值对 tem_str =
  • Decoding URL parameters with JavaScript
    Question This should be a simple task, but I can't seem to find a solution. I have a basic string that is being passed through as a query string parameter like this one: This+is+a+message+with+spaces. I would like to decode that parameter using JavaScript to This is a message with spaces, but I cannot seem to get it to decode. I've tried decodeURI('This+is+a+message+with+spaces') but the result still contains the + signs. Answer1 Yes it is true that decodeURIComponent function doesn't convert + to space. So you have to replace the + using replace function. Ideally the below solution works. var
  • How do I make a textbox that only accepts numbers?
    Question I have a windows forms app with a textbox control that I want to only accept integer values. In the past I've done this kind of validation by overloading the KeyPress event and just removing characters which didn't fit the specification. I've looked at the MaskedTextBox control but I'd like a more general solution that could work with perhaps a regular expression, or depend on the values of other controls. Ideally this would behave such that pressing a non numeric character would either produce no result or immediately provide the user with feedback about the invalid character
  • Regex to match an optional '+' symbol followed by any number of digits
    Question I want a regular expression to match a string that may or may not start with plus symbol and then contain any number of digits. Those should be matched +35423452354554 or 3423564564 Answer1 This should work \+?\d+ Matches an optional + at the beginning of the line and digits after it EDIT: As of OP's request of clarification: 3423kk55 is matched because so it is the first part (3423). To match a whole string only use this instead: ^\+?\d+$ Answer2 It'll look something like this: \+?\d+ The \+ means a literal plus sign, the ? means that the preceding group (the plus sign) can appear 0
  • What does the plus sign do in '+new Date'
    Question I've seen this in a few places function fn() { return +new Date; } And I can see that it is returning a timestamp rather than a date object, but I can't find any documentation on what the plus sign is doing. Can anyone explain? Answer1 that's the + unary operator, it's equivalent to: function(){ return Number(new Date); } see: http://xkr.us/articles/javascript/unary-add/ and in MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Unary_plus Answer2 JavaScript is loosely typed, so it performs type coercion/conversion in certain
  • JavaScript plus sign in front of function expression
    Question I’ve been looking for information about immediately invoked functions, and somewhere I stumbled on this notation: +function(){console.log("Something.")}() Can someone explain to me what the + sign in front of the function means/does? Answer1 It forces the parser to treat the part following the + as an expression. This is usually used for functions that are invoked immediately, e.g.: +function() { console.log("Foo!"); }(); Without the + there, if the parser is in a state where it's expecting a statement (which can be an expression or several non-expression statements), the word
  • What do the plus and minus signs mean in Objective-C next to a method?
    Question In Objective-C, I would like to know what the + and - signs next to a method definition mean. - (void)loadPluginsAtPath:(NSString*)pluginPath errors:(NSArray **)errors; Answer1 + is for a class method and - is for an instance method. E.g. // Not actually Apple's code. @interface NSArray : NSObject { } + (NSArray *)array; - (id)objectAtIndex:(NSUInteger)index; @end // somewhere else: id myArray = [NSArray array]; // see how the message is sent to NSArray? id obj = [myArray objectAtIndex:4]; // here the message is sent to myArray // Btw, in production code one uses "NSArray *myArray"
  • New Google sign in Android
    Question I'm trying to get a user token ID using the new Google play services 8.3 and as documented I pass the server ID: GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestIdToken(getString(R.string.server_client_id)) .requestEmail() .build(); but I'm still getting un successful result as below: {statusCode=unknown status code: 12501, resolution=null} and documented here GoogleSignInStatusCodes The sign-in was cancelled by the user. i.e. the user cancelled some of the sign-in resolutions, e.g. account picking or OAuth consent. Constant Value
  • DBMS_OUTPUT.PUT_LINE not printing
    Question When executing the following code, it just says the procedure is completed and doesn't print the infomation i want it to (firstName, lastName) and then the other values from the select query in a table below. CREATE OR REPLACE PROCEDURE PRINT_ACTOR_QUOTES (id_actor char) AS CURSOR quote_recs IS SELECT a.firstName,a.lastName, m.title, m.year, r.roleName ,q.quotechar from quote q, role r, rolequote rq, actor a, movie m where rq.quoteID = q.quoteID AND rq.roleID = r.roleID AND r.actorID = a.actorID AND r.movieID = m.movieID AND a.actorID = id_actor; BEGIN FOR row IN quote_recs LOOP DBMS
  • How to urlencode a querystring in Python?
    Question I am trying to urlencode this string before I submit. queryString = 'eventName=' + evt.fields["eventName"] + '&' + 'eventDescription=' + evt.fields["eventDescription"]; Answer1 You need to pass your parameters into urlencode() as either a mapping (dict), or a sequence of 2-tuples, like: >>> import urllib >>> f = { 'eventName' : 'myEvent', 'eventDescription' : 'cool event'} >>> urllib.urlencode(f) 'eventName=myEvent&eventDescription=cool+event' Python 3 or above Use: >>> urllib.parse.urlencode(f) eventName=myEvent&eventDescription=cool+event Note that this does not do url encoding in
  • The problem of query optimization in mybatis plus stolen by world hackers
    This article mainly introduces the query optimization problem in mybatis plus. This article introduces you in very detailed, which has a certain reference value for everyone's study or work. Friends who need it can refer to Traditional mybatis plus query writing For regular mybatis single-table query, we can either use LambdaQueryWrapper query or QueryWrapper query. LambdaQueryWrapper has the advantages of preventing miswriting and standardizing code, but the disadvantage is that it cannot be used in complex multi-table queries. In comparison, using QueryWrapper to write queries is more
  • What is the difference between @id and @+id?
    Question I have just started using android, and have about 5 layout files finished. However, I just realized that I have been using @id and @+id interchangeably, but I'm not sure what the exact difference between the two are. Answer1 You need to use @+id when you are defining your own Id for a View. Exactly from docs: The at-symbol (@) at the beginning of the string indicates that the XML parser should parse and expand the rest of the ID string and identify it as an ID resource. The plus-symbol (+) means that this is a new resource name that must be created and added to our resources (in the R
  • Decimal separator comma (',') with numberDecimal inputType in EditText
    Question The inputType numberDecimal in EditText uses the dot . as decimal separator. In Europe it's common to use a comma , instead. Even though my locale is set as german the decimal separator is still the . Is there a way to get the comma as decimal separator? Answer1 A workaround (until Google fix this bug) is to use an EditText with android:inputType="numberDecimal" and android:digits="0123456789.,". Then add a TextChangedListener to the EditText with the following afterTextChanged: public void afterTextChanged(Editable s) { double doubleValue = 0; if (s != null) { try { doubleValue =
  • [Bit Operation-Simple] Interview Question 17.01. Addition without plus sign (review)
    【topic】 Design a function to add two numbers. Do not use + or other arithmetic operators. [Example] Input: a = 1, b = 1 Output: 2 【prompt】 a, b can be negative or 0 The result will not overflow a 32-bit integer [code] [Python] class Solution: def add(self, a: int, b: int) -> int: a &= 0xFFFFFFFF b &= 0xFFFFFFFF print(a) print(b) while b != 0: carry = a & b a ^= b b = ((carry) << 1) & 0xFFFFFFFF return a if a < 0x80000000 else ~(a^0xFFFFFFFF) Origin:https://blog.csdn.net/kz_java/article/details/115264651
  • How can I normalize a URL in python
    Question I'd like to know do I normalize a URL in python. For example, If I have a url string like : "http://www.example.com/foo goo/bar.html" I need a library in python that will transform the extra space (or any other non normalized character) to a proper URL. Answer1 Have a look at this module: werkzeug.utils. (now in werkzeug.urls) The function you are looking for is called "url_fix" and works like this: >>> from werkzeug.urls import url_fix >>> url_fix(u'http://de.wikipedia.org/wiki/Elf (Begriffsklärung)') 'http://de.wikipedia.org/wiki/Elf%20%28Begriffskl%C3%A4rung%29' It's implemented in
  • How to unescape HTML character entities in Java?
    Question Basically I would like to decode a given Html document, and replace all special chars, such as " " -> " ", ">" -> ">". In .NET we can make use of HttpUtility.HtmlDecode. What's the equivalent function in Java? Answer1 I have used the Apache Commons StringEscapeUtils.unescapeHtml4() for this: Unescapes a string containing entity escapes to a string containing the actual Unicode characters corresponding to the escapes. Supports HTML 4.0 entities. Answer2 The libraries mentioned in other answers would be fine solutions, but if you already happen to be digging through real-world html in
  • Append data to a POST NSURLRequest
    Question How do you append data to an existing POST NSURLRequest? I need to add a new parameter userId=2323. Answer1 If you don't wish to use 3rd party classes then the following is how you set the post body... NSURL *aUrl = [NSURL URLWithString:@"http://www.apple.com/"]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:aUrl cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; [request setHTTPMethod:@"POST"]; NSString *postString = @"company=Locassa&quality=AWESOME!"; [request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]]; NSURLConnection
  • Google Play Services in emulator, implementing Google Plus login button etc
    Question When integrating a Google Plus login button in an Android app, I'm observing some differences in how the button appears on an actual device and in the emulator. I am aware of the fact that the Google Plus services APKs are not installed in the emulator, but this can be worked around by pulling the APKs from a device and installing them into the emulator using APK. My current "implementation" simply includes the login button in a layout, by referring to the button with the following XML code: <com.google.android.gms.common.SignInButton android:id="@+id/sign_in_button" android:layout
  • How do I use variables in Oracle SQL Developer?
    Question Below is an example of using variables in SQL Server 2000. DECLARE @EmpIDVar INT SET @EmpIDVar = 1234 SELECT * FROM Employees WHERE EmployeeID = @EmpIDVar I want to do the exact same thing in Oracle using SQL Developer without additional complexity. It seems like a very simple thing to do, but I can't find a simple solution. How can I do it? Answer1 I am using the SQL-Developer in Version 3.2. The other stuff didn't work for me, but this did: define value1 = 'sysdate' SELECT &&value1 from dual; Also it's the slickest way presented here, yet. (If you omit the "define"-part you'll be