html pass a link with get parameters within a link - html

I am trying to pass a link within another in such a way :
http://www.1st_site.com/?u=http://www.2nd_site.com/?parameter1=xyz
I think what the problem is , parameter1=xyz is passed as a parameter for 1st_site
is there anyway to avoid that?

You need to URL-encode the entire URL which is represented as query parameter value, else it will be interpreted as part of the request URL, thus this part: http://www.2nd_site.com/?parameter1=xyz.
It's unclear what programming language you're using, but most of decent webbased languages provides functions/methods/classes to achieve this, e.g. URLEncoder in Java, or c:url and c:param in JSP/JSTL, urlencode() in PHP and escape() in JavaScript.
Here's at least an online URL encoder: http://meyerweb.com/eric/tools/dencoder/. If you input http://www.2nd_site.com/?parameter1=xyz, you should get http%3A%2F%2Fwww.2nd_site.com%2F%3Fparameter1%3Dxyz back so the request URL should effectively end up in:
http://www.1st_site.com/?u=http%3A%2F%2Fwww.2nd_site.com%2F%3Fparameter1%3Dxyz

Related

pass paramter that is a url with parameters

I'm using asp.net mvc
I have a url that have some parameters, one of them is a url
e.g
www.example.com?p1=v1&p2=v2&p3=url&p4=v4...
the url i want to add has few parameters. how can i add them to this url? becuase from the second parameter the first url take them
e.g
www.example.com?p1=v1&p2=v2&p3=www.example2.com?p21=v21&p22=v22&p23=v23&p4=v4...
p21,p22,p23 belongs to the second url (www.example2.com) but the first url (www.example.com) taking p22, p23 has it's own
p.s
i can't control the first url process
Thank you all for your help
You should url encode the value of the query string parameter before sending it in the url:
http://www.example.com?p1=v1&p2=v2&p3=www.example2.com%3Fp21%3Dv21%26p22%3Dv22%26p23%3Dv23%26p4%3Dv4..
So in this example the value of the p3 parameter is properly url encoded for transmission over the HTTP protocol and can be unambiguously decoded back to its original value of www.example2.com?p21=v21&p22=v22&p23=v23&p4=v4 at the receiving site.
There are built-in methods in .NET for achieving this. For example the EscapeDataString method:
string urlEncoded = Uri.EscapeDataString("www.example2.com?p21=v21&p22=v22&p23=v23&p4=v4");
// Will produce: www.example2.com%3Fp21%3Dv21%26p22%3Dv22%26p23%3Dv23%26p4%3Dv4
Of course if you are using the built-in helpers in ASP.NET MVC this url encoding will happen automatically.
If on the other hand you cannot control the building of this url then you will most definitely end up with an ambiguous and wrong url (like the one shown in your question) that no valid system will be able to understand. That's the reason why certain standards have been imposed.

What is the meaning of the '#?' combination in URL

I can't find an answer out there,
Can you tell me what means a #? in an url
# is for intern shortcut / anchor
? is for GET parameters
Example : http://www.roxy.fr/vestes-snowboard-femme/#?camp=da:rx_fr_Cooler_dryflight_bn&ectrans=1
Is it for "no anchor, with these parameters" ?
It seems nonsense to put a # with no anchor name.
Everything following the # is the fragment, or "anchor" as you call it. Your URL has a fragment value of ?camp=da:rx_fr_Cooler_dryflight_bn&ectrans=1. That's right, all this is the fragment. It's styled like a query parameter, and if it would come before the # it would be a query parameter, but as it is it's simply the value of the fragment.
This is likely read by Javascript on the page and evaluated there and the Javascript will fetch some data via AJAX or do something else based on the information in this string. This is typically done when developing a single-page-application or otherwise moving a lot of code to the client-side. The server doesn't receive the fragment and doesn't have to worry about it, it's all done client-side.
In URL syntax, anything after # is a fragment identifier. How it will be used is a different matter and depends on the software that processes the URL. The use of a fragment part in links is just one of the possible uses.

How can we construct custom URLs in HTML form with GET method?

I am using Django for making a website. I am using an HTML form with GET as the method.
The problem is that by default the get url is like this:
/search?name=user&place=place
But I want it to be something like:
my_site/search/user/place
How can that be done?
Why not use POST as method and retrieve the parameters in your view from request.POST? In this way they won't appear in your url.
Also, if you're expecting a list of results i recommend using ListView from views.generic, and in the dispatch() method you'll retrieve your parameters based on which you'll filter the user model (i guess).
It is better with a get request immo, but if you want something like: my_site/search/user/place it is easy, you just have to define the variables in your url and get the arguments in your function.
You can find more detail in django documentation
The only way you can do this in the browser is with Javascript. You will need to build the URL from the form contents. There are many mistakes you can make around encoding the values for the URL. You should be asking why you want to do it this way instead of using the QUERY_PARAMS as the form is doing.
Decoding it with Django isn't that hard, they are just variables in the URL pattern, but unless you have some kind of earth shattering new technology, you should let the browser send them to you without using JS to handcraft the URL.
Using the GET method send data via the web page. This means that the URL can be copied and rechecked at any time.

Passing an HTML parameter in routes (Play framework)

Good day! How are HTML parameters expressed in the routes file? I am trying to pass an HTML but I don't know how. All I know are passing integers ((id: Integer)) and some data types. I tried (content: Html)and (content: Html). I also tried javax.swing.text.html.HTML but it says something about QueryStringBindable. Please help me. Thanks a lot.
Remember that all you pass by route's params will be included in the URL so what is the advantage of using HTML in this place ? GET params should use only simple data types like numerical types, booleans and strings - so you can pass some HTML part as a String (preferably url-encoded or even beter with Base64 encoding).
Much better option is sending it via POST, your URLs won't be terrible long - you won't hit any limitation of URL length, also after common serialization it won't break at special HTML chars.

How would you pass HTTP Headers using a standard anchor tag?

According to the HTML4 reference there's no attribute to pass on HTTP headers using the anchor tag.
I would like to offer a link requesting for a specific file type using the Accept header.
The only way I can see is simply let it be, and pass a GET parameter.
You may as why I would want to do this... I intend to expose a bunch of methods as a public API, serving the results as JSON. And when doing requests using JavaScript, or another programming language, using the Accept header to request a specific response format is "The Right Way" to do it. But that would mean that I need to accommodate both the Accept header and the GET parameter in my code, which smells like a duplication of logic.
This topic is largely debatable, as such links may not be possible to bookmark in the browser... still... I'd like to know if it was possible without too much magic...
I don't see another way than using the GET parameter or an extension like
http://myurl/page?format=json
or better
http://myurl/page.json
Which overrides the accept header (since the browser will only send it's default
accept header). Then you just need to initialize a format to accept header mapping like this (which I don't find duplicate logic at all):
{
"json" : "application/json",
"html" : "text/html"
}
You can't.
I intend to expose a bunch of methods as a public API, serving the results as JSON. And when doing requests using JavaScript, or another programming language, using the Accept header to request a specific response format is "The Right Way" to do it. But that would mean that I need to accommodate both the Accept header and the GET parameter in my code, which smells like a duplication of logic.
If I understand you correctly, you don't have to do this anyway. Browsers already supply an Accept header.
Hmm, seems like if your results are JSON, you will be sending / receiving from script anyway, which can provide any header you want. Just have your link call a script function and you're done.