urlopen module
The urlopen module provides APIs to establish a nonstreaming connection with target servers by HTTP, HTTPS, Kafka, or IBM® MQ protocol and open files in the DataPower® file system. The APIs can also send and receive IBM MQ messages within a GatewayScript action.
To access the APIs in the urlopen module, use the
require('urlopen') statement, such as var urlopen =
require('urlopen');.
The urlopen module provides the urlopen.open() API to
conduct the following behaviors.
- When you need a user agent to establish a connection to the target server dynamically, create a
user agent object and use it in the urlopen.open() API.
- UserAgent object
- The user agent object is used when the urlopen.open() API establishes a connection with the target server by HTTP, HTTPS, or IBM MQ protocol. The UserAgent object is assumed to represent the user agent object.
- HttpUserAgent object
- The HTTP-specific user agent object is used when the urlopen.open() API establishes a connection with the target server by HTTP or HTTPS protocol. The HttpUserAgent object is assumed to represent the HTTP-specific user agent object.
- Establish a connection with the target server by HTTP, HTTPS, or IBM MQ protocol.
- After connections are established, the response from the target server is handled by the
callback parameter of the urlopen.open() API.
- urlopen.open() error responses
- When errors occur, the
urlopen.open()API can receives error codes that provide information to help you recover from errors. - response object
- You can obtain the data by using a read API that is supported by the
responseobject. Theresponseobject is assumed to be initialized by the urlopen.open() API. The read APIs include response.readAsBuffer(), response.readAsBuffers(), response.readAsXML(), and response.readAsJSON().
- urlopen.open() to open a DataPower file