Adding parameters to the request

Top  Previous  Next

You may add parameters to the request using one of two methods.  The method you use may depend on the method allowed by your server and also the amount and complexity of the data you are sending.

 

Appending parameters to the URL

 

Using this method you are simply appending name value pairs to the end of the URL string.  Using this method assumes that the server side CGI script is configured to accept parameter included in the URL string.

 

Example

 

// get response adding fname and lname parameters to URL string

HttpResponse response = session.getResponse("http://www.server.com/path/to/cgi?fname=john&lname=smith");

 

Note

 

When submitting parameters as part of the URL string you must ensure that the parameter names and values are URL encoded to be handled properly.

 

 

Building a HTTP request

 

In the example below we want to submit parameters as part of the HTTP request body.  To do this we must use the HttpRequest class and set the retrieval method to POST.

 

Example

 

// create new HttpRequest

HttpRequest request = new HttpRequest("http://www.server.com/path/to/cgi","POST");

 

// add fname parameter

request.addParameter("fname","john");

 

// add lname parameter

request.addParameter("lname","smith");

 

// get response

 

HttpResponse response = session.getResponse(request);

 

 

 





Home | Company | Products | Solutions | Purchase | Support | Services | Blog

© 2021 JSCAPE LLC