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.
Related
I have a similar but extended question for the below question.
How to pass parameter and json both in http request request body in jmeter??
I will take the same example as mentioned in the above question/link.
Have to pass multiple parameters,
UserId=47
meeting={
"DeviceID":${deviceID},
"NetworkCarrierName":"VODAFONEIN",
"BatteryValue":"22",
"AppVersion":"1.1.3",
}
As you can see, DeviceID have a value from variable deviceID. I want to pass all these parameters and JSON in one single http request body.
What would be the approach for this?
In parameter I have to add the variable for value part for whichever key I want to refer to. It will work fine.
This image shows that..
The same approach will work fine, you can use JMeter Variables anywhere in your test plan, if there is a User Defined Variable or a pre-defined variable or a variable coming from a Post-Processor - JMeter will substitute the variable placeholder with its respective value in the runtime:
If you're uncertain regarding how to properly build your request the easiest is just recording it using HTTP(S) Test Script Recorder
I have this URL: http://localhost:.../home/blogpost/#'I want to get this string'
I get it when pressing:
#item.Title
#item.Title is from my database and that string will change. Now I need to get the 'I want to get this string' string on that page so that I can do a if statement with it, like this:
#if(#item.Title == 'I want to get this string')
Any suggestions?
The target attribute (the part of an URI after the #) is not sent to the server when the browser retrieves the page. So, you cannot get it out of a normal GET or POST request on the server at all.
That data is available in the browser, so you could access it using javascript of even CSS.
Using ajax techniques, you could load a skeleton page and send the target string yourself to the server and have it react to it, and only then load the rest of the page. A bit overkill for most uses I'm afraid and there are drawbacks as well (e.g. search engine might have more trouble to see your content).
It's easier to send the string to the server as a GET parameter if you have the level of control you seem to have. [simply replace the # with a ?], that will be sent to the server by the browser.
Do note that you should URLencode any data you add on to a URL ...
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.
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