I am creating a basic HTML form that will send values to a .jsp page hosted on another domain. As I am not familiar with .jsp, I don't know how it takes parameters,
When I send this URL http://otherdomain.com/login.jsp?username=abc&password=def
It gives me output, but some username contains symbols like '+', etc.
So when trying this URL:
http://otherdomain.com/login.jsp?username=+abc&password=def
It gives me an invalid username or password error.
Please if anyone knows the solution, help me!
You can try url encode for the values you are passing to the url.
You can encode parameter using javascript like this :
encodeURIComponent("ab+c")
and decode parameter in server side :
username = URLDecoder.decode(username)
Generally speaking, login.jsp should be receive request with http post method, you can try to use post method to send parameters to jsp, that's can be avoided encode parameter problem.
Related
I am trying to send a post request with body data where one of the attribute, which passes a list of numbers, requires to be inside the double quotes. I am using something like this [${id}] but it sends the number as [123] when I want it to be sent as ["123"], I have tried several methods to add quotes inside and outside of the curley braces but didn't work. Please advise
Thanks
The correct syntax would be ["${id}"]
You can check what exactly is being sent using View Results Tree listener:
Also assuming you're sending a JSON payload you might also need to add a HTTP Header Manager and configure it to send Content-Type header with the value of application/json
I read on SoloLearn that the method attribute of an input tag within a form can be set to GET or POST. If both methods are sending data to another location, is an HTTP GET being used somehow? I thought GET was used to retrieve data, not send it. Can anyone help me understand, please?
All HTTP requests involve sending something to the server.
A GET request is designed to be used to ask for something.
If you GET http://example.com/ then you ask for the root document for that site.
If you submit the form at https://duckduckgo.com/ then your request is to GET https://duckduckgo.com/?q=example&t=hf&ia=web. You are asking for the search results for the keyword "example".
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.
want to test my url service in browser but need to pass json format data.
I tried the below but no success:
http://locahost:8042/service/getinfo?body={"name":"H&M"}
or any tool that can be use to pass json formatted test data?
UPDATES1
I mean is to pass the json formatted data manually in browser's url address bar. Like as my example above. This is for quick testing only not for implementation.
Yes, you certainly can pass JSON in a URL Querystring. You just have to URLencode the JSON string first. As #dmn said, the data is probably better passed via POST because of GET's size restrictions.
The { and } characters are considered unsafe for unencoded use in a URL.
http://www.faqs.org/rfcs/rfc1738.html
Probably putting it in the GET won't be a good idea, since url parameters have a limit of 256 characters. It would be better if you use POST and put the JSON in the body and after that you can parse it using Jackson for example or gson ... and get the result as an object.
Yes you can Add Extension to chrome web-browser called 'Advance rest Client' and change contain header to application/json and make json object and post in pay load then hit send bottom it works for json object
enter image description here
This is how I am doing in my web service, I am passing a json and within the service I manage it.
Just do a URL query like this:
http://locahost:8042/service/getinfo?name=h%26m
%26 is the encoding of &
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