Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The HTTP/2 functions are used to exchange data over HTTP/2 as a client. However, the functions can also be used for HTTP/1.

The client functions are used to exchange data with a HTTP server. There are specific functions for GET and POST as well as functions for general HTTP requests. Either plain text or encrypted communication can be used. Basic authentication is supported, as well as the use of a keystore, and if required a truststore, for the functions with an encrypted communication channel.

title
Note

Note!

In all parameter descriptions below, "HTTP" may refer to both HTTP and HTTPS, and both HTTP/1 and HTTP/2.

The following functions for HTTP/2 described here are:

Table of Contents
maxLevel1

httpGet

This function uses the GET method to retrieve content from an HTTP server.

Code Block
string httpGet
    ( string host,
      string path,
      string protocol,			    //Optional
      int port,                     //Optional
      boolean secure,               //Optional
      int requestTimeout,           //Optional
      int connectionTimeout,        //Optional
      string username,              //Optional
      string password,              //Optional
      map<string, string> headers ) //Optional


Parameter

Description

host

The name or IP address of the HTTP server.

path

The path.

Info
title

Example - path


Code Block
/api/v2/doc



protocol

The protocol used: HTTP/1 or HTTP/2. The default value is HTTP/1. To use HTTP/2, you must set this value to "h2".

port

The port number to contact the HTTP server on. Port 80 is used for HTTP connection and 443 is used for HTTPS connection by default.

secure

Indicates whether the data should be sent in secure mode or not.

requestTimeout

The number of milliseconds to wait for a response. If the value is not specifically specified, the default timeout is used. The default value is 15000 milliseconds.

connectionTimeout

The number of milliseconds to wait for a connection to be established. If the value is not specifically specified, the default timeout is used. The default value is 3000 milliseconds.

username

A username for an account on the HTTP server.

password

Password associated with the username.

headers

Custom HTTP request headers.

Returns

Content from the HTTP server. It will be null if any part of the communication fails.

httpPost

This function uses the POST method to send content to an HTTP/2 server and receives the response.

Code Block
string httpPost
    ( string host, 
      string path,		
      bytearray content, 
      string contentType,
      string protocol,			    //Optional
      int port,                     //Optional 
 	  boolean secure,               //Optional 
      int requestTimeout,           //Optional
      int connectionTimeout,        //Optional 
      string username,              //Optional
      string password,              //Optional
      map<string, string> headers ) //Optional


Parameter

Description

host

The name or IP address of the HTTP server. 

path

The path

Info
title

Example - path


Code Block
/api/v2/doc



bytarraycontent

The body of the request in bytearray format.

contentType

The MIME type of the content.

Info
title

Example - contentType


Code Block
application/json



protocol

The protocol used: HTTP/1 or HTTP/2. The default value is HTTP/1. To use HTTP/2, you must set this value to "h2".

port

The port number to contact the HTTP server on. Port 80 is used for HTTP connection and 443 is used for HTTPS connection by default.

secure

Indicates whether the data should be sent in secure mode or not.

requestTimeout

The number of milliseconds to wait for a response. If the value is not specifically specified, the default timeout is used. The default value is 15000 milliseconds.

connectionTimeout

The number of milliseconds to wait for a connection to be established. If the value is not specifically specified, the default timeout is used. The default value is 3000 milliseconds.

username

A username for an account on the HTTP server.

password

Password associated with the username.

headers

Custom HTTP request headers.

Returns

Content from the HTTP server. It will be null if any part of the communication fails.

httpReq

This function makes an HTTP request and uses the specified method, for example GET, POST, and PUT.

Code Block
string httpReq
    ( string method,	
	  string host,	
      string path,
      bytearray content,
      string contentType, 
	  string protocol,			    //Optional
	  int port,					    //Optional
	  boolean secure,			    //Optional
      int requestTimeout,		    //Optional
	  int connectionTimeout,	    //Optional
	  string username,			    //Optional
	  string password, 			    //Optional
      map<string,string> headers )//Optional


Parameter

Description

method

The HTTP method.

host

The name or IP address of the HTTP server. 

path

The path

Info
title

Example - path


Code Block
/api/v2/doc



content

The body of the request in bytearray format.

contentType

The MIME type of the content.

Info
title

Example - contentType


Code Block
application/json



protocol

The protocol used: HTTP/1 or HTTP/2. The default value is HTTP/1. To use HTTP/2, you must set this value to "h2".

port

The port number to contact the HTTP server on. Port 80 is used for HTTP connection and 443 is used for HTTPS connection by default.

secure

Indicates whether the data should be sent in secure mode or not.

requestTimeout

The number of milliseconds to wait for a response. If the value is not specifically specified, the default timeout is used. The default value is 15000 milliseconds.

connectionTimeout

The number of milliseconds to wait for a connection to be established. If the value is not specifically specified, the default timeout is used. The default value is 3000 milliseconds.

username

A username for an account on the HTTP server.

password

Password associated with the username.

headers

Custom HTTP request headers.

Returns

A response from the HTTP server. It will be null if any part of the communication fails.

httpMultipartPost

This function uses the POST method to send multipart binary contents to an HTTP server and receives the response.

Code Block
bytearray httpMultipartPost
    ( string host,
	  string path,
	  list<MultipartSegmentUDR> content,
	  string protocol,			    //Optional
   	  int port, 				    //Optional 
	  boolean secure,			    //Optional
      int requestTimeout,		    //Optional
	  int connectionTimeout,	    //Optional
      string username,              //Optional
      string password,              //Optional
      map<string, string> headers ) //Optional


Parameter

Description

host

The name or IP address of the HTTP server. 

path

The path on the server to which we should do the POST.

content

The body of the the request.

protocol

The protocol used: HTTP/1 or HTTP/2. The default value is HTTP/1. To use HTTP/2, you must set this value to "h2".

port

The port to be used for the HTTP server. Port 80 is used for HTTP connection and 443 is used for HTTPS connection by default.

secure

Indicates whether the data should be sent in secure mode or not.

requestTimeout

The number of milliseconds to wait for a response. If the value is not specifically specified, the default timeout is used. The default value is 15000 milliseconds.

connectionTimeout

The number of milliseconds to wait for a connection to be established. If the value is not specifically specified, the default timeout is used. The default value is 3000 milliseconds.

username

Username for the account to be used on the HTTP server.

password

Password associated with the username.

headers

Custom HTTP request headers.

Returns

A bytearray from the HTTP server. It will be null if any part of the communication fails.


title
Note

Note!

For optional parameters, you need to state null in case you supply subsequent optional parameters. If there are no subsequent parameters, you do not have to state anything.

Info
titleExample


Code Block
httpMultipartPostURL( "mypath", mybody, "myhost", 0, null, "myusername");



...

To specify a Keystore file that you want to use, set the properties https.apl.keystore_location and https.apl.keystore_passphrase in the relevant ECs. See the example below for how to set these properties using the mzsh topo command.


title
Info

Example - Setting Java keystore properties


Code Block
$ mzsh topo set topo://container:<container>/pico:<pico>/val:config.properties.https.apl.keystore_location <location of the Keystore file>
$ mzsh topo set topo://container:<container>/pico:<pico>/val:config.properties.https.apl.keystore_passphrase <DR encrypted password>


If the two properties above are not set in the relevant Execution Context <pico>.conf, MZ Default Keystore is used.

The property  https.apl.keystore_location  represents the location of the keystore and the property  https.apl.keystore_passphrase  represents the passphrase for that keystore.

...

Code Block
keytool -keystore /var/opt/mz/HttpdExec.keystore -genkey -keyalg RSA


Note
title

Note!

The Keystore passphrase must be the same as the passphrase used by the certificate.

...

A truststore is a keystore that is used when deciding what to trust - truststore stores certificates from third parties. If you receive data from an entity that you already trust, and if you can verify that the entity is what it claims to be, you can assume that the data does in fact come from that entity.

By Default, Image Modified uses its own truststore, which always trusts any server connection.

If you want to use a specific truststore, use the mzsh topo command to add the property https.apl.userdefined.truststore to the required ECs and set the value to true:

Code Block
theme
languagetextEclipse
$ mzsh topo set topo://container:<container>/pico:<pico>/val:config.properties.https.apl.userdefined.truststore true

...

After setting the property https.apl.userdefined.truststore to true, if you want to use a specific truststore, use the mzsh topo command to set the following properties in the relevant ECs:

  • https.apl.truststore_location

  • https.apl.truststore_passphrase


title
Info

Example - Setting properties to use a specific truststore


Code Block
$ mzsh topo set topo://container:<container>/pico:<pico>/val:config.properties.https.apl.truststore_location <location of the truststore file>
$ mzsh topo set topo://container:<container>/pico:<pico>/val:config.properties.https.apl.truststore_passphrase <DR encrypted password>



If you do not set these two properties, the Java Default Truststore is used.


Scroll pagebreak