Is it possible to use apache's URIBuilder to set a parameter with percentage sign? - urlencode

I want to build this complete URL:
locahost/some/path?param1=%06
using org.apache.http.client.utils.URIBuilder method setParameter(final String param, final String value). At its javadoc, there's line:
The parameter name and value are expected to be unescaped and may contain non ASCII characters
But when I use setParameter("param1","%06") I always get ...param1=%2506 instead of ...param1=%06. Looking here I noticed percent sign is 25 in hex.
Should I parse this manually or there's a way to keep using URIBuilder and keep the parameters as is?

Related

URL-parameters input seems inconsistent

I have review multiple instructions on URL-parameters which all suggest 2 approaches:
Parameters can follow / forward slashes or be specified by parameter name and then by parameter value. so either:
1) http://numbersapi.com/42
or
2) http://numbersapi.com/random?min=10&max=20
For the 2nd one, I provide parameter name and then parameter value by using the ?. I also provide multiple parameters using ampersand.
Now I have see the request below which works fine but does not fit into the rules above:
http://numbersapi.com/42?json
I understand that the requests sets 42 as a parameter but why is the ? not followed by the parameter name and just by the value. Also the ? seems to be used as an ampersand???
From Wikipedia:
Every HTTP URL conforms to the syntax of a generic URI. The URI generic syntax consists of a hierarchical sequence of five components:
URI = scheme:[//authority]path[?query][#fragment]
where the authority component divides into three subcomponents:
authority = [userinfo#]host[:port]
This is represented in a syntax diagram as:
As you can see, the ? ends the path part of the URL and starts the query part.
The query part is usually a &-separated string of name=value pairs, but it doesn't have to be, so json is a valid value for the query part.
Or, as the Wikipedia articles says it:
An optional query component preceded by a question mark (?), containing a query string of non-hierarchical data. Its syntax is not well defined, but by convention is most often a sequence of attribute–value pairs separated by a delimiter.
It is also fairly common for request processors to treat a name=value pair that is missing the = sign, as if the it was name=.
E.g. if you're writing Servlet code and call servletRequest.getParameter("json"), it would return an empty string ("") for that last URL in the question.

Can Bitly shorten percent symbol contained URL?

I have been trying to shorten URL contains % symbol to bitly shorten API:
Examples
My Original URL:
https://www.google.com?param=40%OFF
Doesn't work
https://api-ssl.bitly.com/v3/shorten?access_token=...&longUrl=https%3A%2F%2Fwww.google.com%3Fparam%3D40%25+OFF
When I try to eliminate the percent from URL, then encoded it again, it works:
https://api-ssl.bitly.com/v3/shorten?access_token=...&longUrl=https%3A%2F%2Fwww.google.com%3Fparam%3D40+OFF
I am not able to find Bitly doc states it does not able to shorten percent contained URL
Anyone has advise?
The URL you're passing to shorten isn't a syntactically valid URL. Perhaps you meant ...&longUrl=https%3A%2F%2Fwww.google.com%3Fparam%3D40%2525OFF, which when decoded gives longUrl the value https://www.google.com?param=40%25OFF, which when decoded gives param the value 40%OFF. Without the "extra" 25, decoding fails at the second step since O isn't a hexadecimal digit.

How i get a continuation of a value with Extractor (JMETER)?

I am trying to take the Information from an element from the middle on.
And this value is only displayed this way
see image:
It would be the value "info_se"
You need to escape ? sign (as well as other meta characters) in your regular expression with a back slash so the whole expression would be something like:
a href="#" data-url="Cervello/Release.aspx\?info_s=(.+?)"
Demo:
References:
JMeter Regular Expressions
Using RegEx (Regular Expression Extractor) with JMeter
Perl 5 Regex Cheat sheet
Use regular expression extractor under your sampler that return the full html. Save in reference name as info and then use it later ${info}
info_s=(\S+)"
Template $1$
Match No. 1
My error was another, this "info_s" field was decoded, so the system needs this coded encoding.
I managed to find several that stored this value, and in the parameters of HTTP request, I was informed to code the extracted value of the Extractor
I get, finding in the html the field that stored this value "info_s", decoded, then using the encoder option of jmeter, I was able to capture the correct value.

How to search within a URL field in Solr? (like *wildcard*)

In Solr I have a field dedicated to URLs. The URL field can be anywhere up to 2000 in length. However, I only ever need to search the first 200 characters.
Example URL:
https://www.google.co.uk/search/2014/here/?q=help+me&oq=stackoverflow&aqs=c
I've experimented over the last 2 weeks with Grams and various combinations of Tokenizers to no avail. I always seem to fall short. I would provide examples but they are all standard so no point cluttering this with non-working types.
The main problem seems to be with how Solr deals with punctuation. It treats non-A-z/0-9 characters as separators. How do I disable this for a field?
For example I can search: 'google' and get the correct result, but when I search 'google.co' nothing comes back. Same problem with most of the non-A-z/0-9 characters, it seems to treat them as a separator.
Everything needs to be *wildcard*searchable from 4char strings up to 200 char strings.
So the following search terms would return the above result. '&aqs','ow&aqs=','ps://www.goo','q=help+','2014/he'... etc
How would you define a field type for the URL wildcard use case?
You can use a string field for your url and use a filter that cuts it off to 200 characters.It can be a regex expressions also to keep only 200 characters for that field.
String field will match the exact tokens

Usage of url_encode

I tried using Ruby's url_encode (doc here.)
It encodes http://www.google.com as http%3A%2F%2Fwww.google.com. But it turns out that I cannot open the latter via a browser. If so, what's the use of this function? What is it useful for, when the URL that it encodes can't even be opened?
A typical use is the HTTP GET method, in where you need a query String.
Query String 1:
valudA=john&valueB=john2
Actual value server get:
valueA : "john"
valueB : "john2"
url_encode is used to make the key-value pair enable to store the string which includes some non-ASCII encoded character such as space and special character.
Suppose the valueB will store my name, code 4 j, you need to encode it because there are some spaces.
url_encode("code 4 j")
code%204%20j
Query string 2:
valueA=john&valueB=code%204%20j
Actual value server get:
valueA: "john"
valueB: "code 4 j"
You can use url_encode to encode for example the keys/values of a GET request.
Here is an example of what a SO search query URL looks after encoding:
https://stackoverflow.com/questions/tagged/c%23+or+.net+or+asp.net
As you can see, url encoding appears to be applied only on the last part of the URL, after the last slash.
In general you cannot use url_encode on your entire URL or you will also encode the special characters in a normal URL like the :// in your example.
You can check a tutorial that explains how it works here: http://www.permadi.com/tutorial/urlEncoding/