Proxy Server API

Overview

screen-scraper provides three built-in objects for proxy sessions. These objects are: proxySession, request, and response. See the Variable scope section for details on which objects are available based on when scripts are run.

proxySession

Overview

This object gives you the ability to control interactions with the proxy session. It is only for use in scripts that associated with proxy sessions.

getVariable

Object proxySession.getVariable ( String identifier )

Description

Retrieve the value of the proxy session variable.

Parameters

  • identifier Name of the session variable, as a string.

Return Values

Returns the value of the session variable.

Change Log

Version Description
4.5 Available for all editions.

Examples

Retrieve Session Variable

 // Places the proxy variable "CITY_CODE" in
 // the local variable "cityCode"

 cityCode = proxySession.getVariable( "CITY_CODE" );

See Also

  • setVariable() [proxySession] - Sets the value of a proxy session variable

log

void proxySession.log ( String message )

Description

Write to the log.

Parameters

  • message Message to be written to the log, as a string.

Return Values

Returns void.

Change Log

Version Description
4.5 Available for all editions.

Examples

Write to Log

 // Writes "Inserting request parameters into the database."
 // to the proxy session log

 proxySession.log( "Inserting request parameters into the database." );

setVariable

void proxySession.setVariable ( String identifier, Object value )

Description

Set the value of a proxy session variable.

Parameters

  • identifier Name of the session variable, as a string.
  • value The value to be assigned to the session variable.

Return Values

Returns void.

Change Log

Version Description
4.5 Available for all editions.

Examples

Set Session Variable

 // Sets the variable "CITY_CODE" in the proxySession
 // to be equal to the value of the get method of the dataSet
 proxySession.setVariable( "CITY_CODE", dataSet.get( 0, "CITY_CODE" ) );

See Also

  • getVariable() [proxySession] - Gets the value of a proxy session variable

request

A request objects references a proxySession page request. Through this object you can control various aspects of the request.

Scripts run in the scraping engine use the scrapeable file to manipulate server requests.

addHTTPHeader

void request.addHTTPHeader ( String key, String value )

Description

Manually add an HTTP header.

Parameters

  • key Name of the HTTP header, as a string.
  • value Value to be associated with the header, as a string.

Return Values

Returns void.

Change Log

Version Description
4.5 Available for all editions.

Examples

Add HTTP Header

 // Set Cookie header to someCookieValue
 request.addHTTPHeader( "Cookie" , "someCookieValue");

See Also

addPOSTParameter

void request.addPOSTParameter ( String key, String value )

Description

Add POST parameter to HTTP request.

Parameters

  • key Name of the POST parameter, as a string.
  • value Value of the POST parameter, as a string.

Return Values

Returns void.

Change Log

Version Description
4.5 Available for all editions.

Examples

Add POST Parameter

 // Add selectedState parameter to the POST variables
 // with a value of Alaska

 request.addPOSTParameter( "selectedState" , "AL");

See Also

getURLAsString

String request.getURLAsString ( String key )

Description

Retrieve the URL of the request.

Parameters

This method does not receive any parameters.

Return Values

Returns the URL of the request, as a string.

Change Log

Version Description
4.5 Available for all editions.

Examples

Retrieve Request URL

 // Retrieve the URL String
 url = request.getURLAsString();

removeHTTPHeader

void request.removeHTTPHeader ( String key, String value )

Description

Manually remove an HTTP header. Both the key and value have to be specified as HTTP headers allow for multiple headers with the same key.

Parameters

  • key Name of the HTTP header, as a string.
  • value Value to be associated with the header, as a string.

Return Values

Returns void.

Change Log

Version Description
4.5 Available for all editions.

Examples

Remove HTTP Header

 // Remove the Cookie header with the value someCookieValue
 request.removeHTTPHeader( "Cookie" , "someCookieValue");

See Also

removePOSTParameter

void request.removePOSTParameter ( String key )

Description

Remove POST parameter from HTTP request.

Parameters

  • key Name of the POST parameter, as a string.

Return Values

Returns void.

Change Log

Version Description
4.5 Available for all editions.

Examples

Remove POST Parameter

 // Removes the POST parameter selectedState
 request.removePOSTParameter( "selectedState" );

See Also

setRequestLine

void request.setRequestLine ( String requestMethod, String url, String httpVersion )

Description

Manually set the request line.

Parameters

  • requestMethod HTTP request type, as a string.
  • url Valid uri, as a string.
  • httpVersion HTTP version, as a string.

Return Values

Returns void.

Change Log

Version Description
4.5 Available for all editions.

Examples

Set Request Line

 // Sets the request line on the request
 request.setRequestLine( "GET" , "http://somesite.com/somepage.html", "HTTP/1.1");

response

The response class provides you with a means for editing the responses received by the proxy server.

Scripts run in the scraping engine us the scrapeable file to manipulate server responses.

addHTTPHeader

void response.addHTTPHeader ( String key, String value )

Description

Add HTTP header to response.

Parameters

  • key Name of the header, as a string.
  • value Value associated with the header, as a string.

Return Values

Returns void.

Change Log

Version Description
4.5 Available for all editions.

Examples

Add HTTP Header

 // Adds the HTTP Header Set-Cookie with a value
 // of someCookieValue

 response.addHTTPHeader( "Set-Cookie" , "someCookieValue");

See Also

getContentAsString

String response.getContentAsString ( )

Description

Retrieve the content of the response.

Parameters

This method does not receive any parameters.

Return Values

Returns the content of the response, as a string.

Change Log

Version Description
4.5 Available for all editions.

Examples

Get the Response Text

 // Retrieve the contents of the response
 content = response.getContentAsString();

See Also

getStatusLine

String response.getStatusLine ( )

Description

Retrieve the status line of the response.

Parameters

This method does not receive any parameters.

Return Values

Returns the status line of the response, as a string.

Change Log

Version Description
4.5 Available for all editions.

Examples

Get the Status Line Text

 // Retrieve the status line of the response
 statusLine = response.getStatusLine();

See Also

removeHTTPHeader

void response.removeHTTPHeader ( String key, String value )

Description

Remove HTTP header from response.

Parameters

  • key Name of the header, as a string.
  • value Value associated with the header, as a string.

Return Values

Returns void.

Change Log

Version Description
4.5 Available for all editions.

Examples

Remove HTTP Header

 // Remove the HTTP Header Set-Cookie that has a
 // value of someCookieValue

 response.removeHTTPHeader( "Set-Cookie" , "someCookieValue");

See Also

setContentAsString

void response.setContentAsString ( String content )

Description

Manually set the response content.

Parameters

  • content Response text, as a string.

Return Values

Returns void.

Change Log

Version Description
4.5 Available for all editions.

Examples

Change the Response Text

 // Supply your own content to the response
 response.setContentAsString( "<html> ... </html>");

See Also

setStatusLine

void response.setStatusLine ( String statusLine )

Description

Manually set the status line.

Parameters

  • statusLine New status line declaration, as a string.

Return Values

Returns void.

Change Log

Version Description
4.5 Available for all editions.

Examples

Set Status Line

 // Set the status line to HTTP/1.1 200 OK
 response.setStatusLine( "HTTP/1.1 200 OK" );

See Also