pass URL-encoded URL to CURL - url

How do i pass a URL-encoded URL to CURL?
Ex:
curl "http://live.nwk5.net/secure/v.stream/playlist.m3u8?expiry=kFmysuf%2fLjOqgdXGJWqFQA%3d%3d"
This returns a invalid page.
if I URL decode the parameter as below, Im getting the expected response. Please Help.
curl "http://live.nwk5.net/secure/v.stream/playlist.m3u8?expiry=kFmysuf/LjOqgdXGJWqFQA=="

You're talking in vague terms. curl accepts and expects a URL. You need to provide the correct URL as curl can't guess what you otherwise intended.
If you have the URL encoded into weirdness, you have to first decode it to tell curl the correct URL.
URL-encoding a URL an extra time like you seem to have done partly (because otherwise you would also have encoded the slashes etc), is what I consider "encoded into weirdness".

Related

Does YouTube support oEmbed?

This suggests it does :
https://youtube-eng.googleblog.com/2009/10/oembed-support_9.html
But I'm getting nothing back when I do, say
curl "https://www.youtube.com/oembed" -d 'format=json' -d 'url=https://www.youtube.com/watch?v=uXBDgLglFig'
Does anyone know if the oembed API has been deprecated?
You're making a POST request with those options you're passing to curl. You need to make a GET request instead, like so:
curl 'https://www.youtube.com/oembed?format=json&url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DuXBDgLglFig'
Note that the URL parameter must be URL encoded. How you do that depends on what language you're using to make the request.

How to use url encoded data in get method?

I am working on a restful service in asp.net MVC 4 Web API. I have a get method that getting a url encoded data as a parameter from URI. But, the thing is when I try this method from RESTClient (firefox tool), I am getting 404. And when i check the stack trace my url seems with non encoded parameter. You can see the example below:
Url format: /api/Applications/key
I am sending this:
/api/Applications/3baxYhYzpVGTrIIzs4CvGv4KIcIRHn5yqx%2F9a5PzTJxK4SWVcwi9GI6bib9pe1psk%2FdYeD0EaOdMHZpzWl%2Fbwg%3D%3D
In the response body, request url seems like this;
/api/Applications/3baxYhYzpVGTrIIzs4CvGv4KIcIRHn5yqx/9a5PzTJxK4SWVcwi9GI6bib9pe1psk/dYeD0EaOdMHZpzWl/bwg==
I am getting an error because of escape characters. I can use post but I want to go on with restful architecture.
Any advice will be appreciated.

Use base64 encoded string in url cakephp

here is the solution for php Passing base64 encoded strings in URL
but because of urlencode cakephp problem I cant use it (the solution in there is not good for me)
Passing an urlencoded URL as parameter to a controller / action at CakePHP
Rawurlencode does not work either. Also I cant hash it because I need it to be reversible. Or is there some "reversible" hash function. I know that the meaning of hash is for one way, but like some way to get output similar(so I can use in the url without problems) to md5/sha* but be able to reverse.
QSN: how to use base64 encoded string in url to avoid problems, mentioned in the above link.

How exactly does Url Encoding work?

In MVC, I'm attempting to use URL routing to get the result of an action given a certain input.
Consider the following in my view:
<%=Html.ActionLink("View", "Test", new with {.id = Url.Encode(dir\file}) %>
My controller then uses HttpUtility.UrlDecode(id) to get the original. The controller itself is using File() to retrieve a file at the specified directory\file location. However, an error message pops up telling me that
A potentially dangerous Request.Path value was detected from the client (%).
The URL is showing up as
http://home/dir%255cfile.txt
I googled Url Encoding and \ is encoded as %5c. Where is the %25 coming from? It's the encoding for %, but that means Encode is being done twice. Why is that, and is that supposed to be happening?
Html.ActionLink takes care of the URL encoding for you. If you don't encode the params there, there's no need to decode it again and your issue is solved.

Do I need to encode strings (eg URL) I pass as a POST form parameter

Do I need to encode strings (eg URL) I pass as a POST form parameter?
Ie I want to pass a URL I have to my web application (ruby on rails) as one of the form parameters. So are there any potential characters in a URL/URI that would need to be encoded? Or perhaps rails would handle this anyway?
Do I need to encode strings (eg URL) I pass as a POST form parameter?
That depends on what you're using to create/send your POST request. If you're directly creating the request body yourself, then yes you would have to URL-encode each parameter:
POST / HTTP/1.1
Content-Type: application/x-www-form-urlencoded
foo=bar&url=http://www.example.com/url?innerparameter1=1&innerparameter2=2
this is no good:innerparameter2 is actually a parameter of the outer form-encoded string. It would need encoding, which would look like:
foo=bar&url=http%3A//www.example.com/url%3Finnerparameter1%3D1%26innerparameter2%3D2
If, however, you are using something higher-level to make the POST request, and passing in some kind of mapping of parameter strings, I would expect that component to take care of the URL-encoding for you.
Code?
As bobince mentions, you need to encode any data that you're passing as URL parameters. Often whatever library you're using will take care of this. This applies to all HTTP requests BTW.
For example, an API has an endpoint GET /sites/:name.
Using cURL it should look like
curl http://example.com/sites/google%2Ecom
In Ruby/Rails, you can use URI.encode and URI.decode:
>> URI.encode('google.com', /\W/)
"google%2Ecom"
>> URI.decode('google%2Ecom')
"google.com"
As a general statement, if you emit programmatic or user input data to an HTML page, you should encode it for HTML. Bear in mind that URLs often have the & character and that should be encoded, even if browsers appear to handle it okay.
I'm not a Ruby guy, so I don't know how you do that in Ruby, nor am I familiar with Ruby on Rails to say if it will do it (though I would be a little surprised by that), but the guideline I suggest isn't language specific.

Resources