Is this URL valid?
/path_A?param=value/path_B/path_C
after the parameters, there are more stuff.
Yes that URL is valid, but it probably won't be parsed the way you want.
The path is /path_A
The query string is param=value/path_B/path_C
The value of param is value/path_B/path_C
Related
I have a base url that i want to redirect the user to, but this url have another url in its query param
for ex:
base_url = "https://www.base.com?origin=#{origin_url}"
the origin url itself have some query params
origin_url = 'https://www.origin.com?utm_source=foo&utm_term=bar'
but there is a problem with that, if I just use this url it comes like this
https://www.base.com?origin=https://www.origin.com?utm_source=foo&utm_term=bar
with that url, the &utm_term becomes a query string for the base url, and not for the origin url
is there a special type of encoding to deal with this nested query string problem ?
I've tired use URI.encode_www_form_component in the origin_url, and I got
https%3A%2F%2Fwww.origin.com%3Futm_source%3Dfoo%26utm_term%3Dbar
so the Full url became
https://www.base.com?origin=https%3A%2F%2Fwww.origin.com%3Futm_source%3Dfoo%26utm_term%3Dbar
but the problem is that I always decode the url before redirect, so it just get decoded again.
Here is an example of how I passed my value through the URL; If I correctly remember, to pass any key/value in the URL, I just need to use the "?" after the URL and add my "key" and "value".
The error I get is a "401 unauthorized".
For query parameter, your should use code as shown below
https://<APP_NAME>.azurewebsites.net/api/<FUNCTION_NAME>?code=<API_KEY>
If by Http header then use x-functions-key.
Documentation
Suppose I am expecting a url as part of my route - maybe a callback url or similar - I might use the following route:
get '/mymodel/:url', to: 'mycontroller#docallback', url: /.*/
Now I would like to be able to go to http://www.myapp.com/mymodel/http://www.google.co.uk/ and process http://www.google.co.uk/ in mycontroller - but it is processed as http:/www.google.co.uk/ (one slash). How can I rectify this? Is the regex wrong or is there some flag I have to set?
I don't think that "http://www.myapp.com/mymodel/http://www.google.co.uk/" is a valid url.
Normally if you want to pass a url as a parameter you would call CGI.escape on it first, which would convert "http://www.google.co.uk/" to "http%3A%2F%2Fwww.google.co.uk%2F" CGI.escape will turn any string into a url-safe version of itself, basically replacing any characters which have a special function in a url, like ":/?&" and also space and some other characters which would otherwise break the formatting.
So, you would end up with a url like
"http://www.myapp.com/mymodel/http%3A%2F%2Fwww.google.co.uk%2F"
which would come through in params like
params = {:url => "http://www.google.co.uk/"}
Note how it's been unescaped here: Rails automatically* calls CGI.unescape on parameter values before putting them into the params hash.
However, this url
"http://www.myapp.com/mymodel/http%3A%2F%2Fwww.google.co.uk%2F"
looks pretty weird to me. It would be better to be more explicit and pass it through as a named parameter in the url itself, like
"http://www.myapp.com/mymodel?url=http%3A%2F%2Fwww.google.co.uk%2F"
which will require a slight change to your routes.
* I think Rails will do this but it might depend on circumstances. Try it.
...Turned out that the request was not encoded on the client side before being sent, solution was to use encodeURIComponent() on the url before sending it.
Basically I need to pass three paramaters to a http as get. Here are the parameters
param1 = 3
param2 = 454
param3 = http://localhost:3000/another_test?another_param=4&another_param2=978
This transforms to
http://localhost:3000/test?param1=3¶m2=454¶m3=http://localhost:3000/another_test?another_param=4&another_param2=978
I am just confused whether the URL formed is correct or not. Will this work or is there anyother way to do this. I am using Rails. I did a decode and clicked on the link and I still see the above URL coming. Will this work on the receiever side, meaning will it be decoded as I had intended.
Please advise.
It should work as long as you url encode the params. In that case the & and ? will be transformed, making it possible for Rails to differentiate between the query string parameters and the query string delimiters.
To ensure that it is encoded you can use Rack::Utils.escape or Hash#to_query.
This will be decoded as:
param1=3
param2=454
param3=http://localhost:3000/another_test?another_param=4
another_param2=978
You need to encode param3, or at minimum replace the ampersands in it with the correct URL encoding, in order for it to match back up to your input parameters.
This is the request Facebook calls back:
/facebook/promo/#access_token=162592277090170%7C2.yCch3otjrdit_rgBFS6F0A__.3600.1285369200-727781553%7CtugQmoO0bRiadumHVQrrSiPRD9Y&expires_in=7174
How can I parse the access_token from the URL? I could not find any way to get the access_token value.
Please be aware that it is not a reqular parameter.
You could use a Regex to match it out of the url. Or simply take everything as a sub-string between access_token= and the next &-character or the end of the url, which ever comes first.
I believe that it's not possible - the part after # is simply ignored. See this answer: Rails: Extracting the raw url from the request
If you're only after the access_token=... section, just use some simple string matching:
url = '/facebook/promo/#access_token=162592277090170%7C2.yCch3otjrdit_rgBFS6F0A__.3600.1285369200-727781553%7CtugQmoO0bRiadumHVQrrSiPRD9Y&expires_in=7174'
url[/#access_token=(.+)&/, 1]
=> "162592277090170%7C2.yCch3otjrdit_rgBFS6F0A__.3600.1285369200-727781553%7CtugQmoO0bRiadumHVQrrSiPRD9Y"
That looks for #access_token= and grabs everything up to &.