Printing the URL parameter in name value pair
Requirement:
If the complete URL is know probably this program would help in printing the url parameters in name-value pair using java.
I used it for the below reason:
In order to validate the security vulnerabilities like XSS, SQL Injection, etc. IBM APPSCAN tool was used, the report should be analyzed to verify the issue.
The report has the url that was used to get the response, most of the times the URL was too big and difficult to interpret so i was going thorough java docs to find a way to print the parameters of the URL so that it would be human readable format.
Below was the code i was using, it was useful
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URLEncodedUtils;
public class ReadURLNameValue {
static String urlVal = "http://www.domain.com/index.jsp?name=urname&city=&pincode=1231";
public static void main (String args[]) throws URISyntaxException
{
List<NameValuePair> params = URLEncodedUtils.parse(new URI(urlVal), "UTF-8");
for (NameValuePair param : params) {
System.out.println(param.getName() + " : " + param.getValue());
}
}
}
OUTPUT:
name : urname
city: null
pincode : 1231
No comments:
Post a Comment