Search

User Manual

GETTING STARTED


MODULES AND PLATFORM


APPENDIX


TUTORIALS & HELPFUL TRICKS


GLOSSARY


STRATEGIC PARTNER LINKS

Sepasoft - MES Modules
Cirrus Link - MQTT Modules

RESOURCES

Inductive University
Ignition Demo Project
Knowledge Base Articles
Forum
IA Support
SDK Documentation
SDK Examples

ALL MANUAL VERSIONS

Ignition 8.1
Ignition 7.9
Ignition 7.8

Deprecated Pages

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 16 Next »


This function is used in Python Scripting.

Description

Provides a general use object that can be used to send and receive RESTful HTTP requests. The object created by this function is a wrapper around Java's HttpClient class. Typical use involves creating the a JythonHttpClient object with a call to system.net.httpClient, and then utilizing the varous methods (get(), post(), etc) on the JythonHttpClient to handle requests.

Client Permission Restrictions

This scripting function has no Client Permission restrictions.

Syntax

system.net.httpClient()

  • Parameters

Integer timeout - A value, in milliseconds, to set the client’s connect timeout setting to. [Optional - Defaults to 60000]

Boolean bypass_cert_validation - A value, in milliseconds, to set the client’s read timeout setting to. [Optional - Defaults to False]

String username - A string indicating the username to use for authentication if the remote server requests authentication; specifically, by responding with a WWW-Authenticate or Proxy-Authenticate header. Only supports Basic authorization. If username is present but not password, an empty string will be used for password. [Optional - Defaults to None]

String password - A string indicating the password to use for authentication. [Optional - Defaults to None]

String proxy - The address of a proxy, which will be used for HTTP and HTTPS traffic. If the port is not specified, it will be assumed from the protocol in the URL, i.e. 80/443. [Optional - Defaults to None]

String cookie_policy - A string representing this client’s cookie policy. Accepts values "ACCEPT_ALL", "ACCEPT_NONE", and "ACCEPT_ORIGINAL_SERVER" . [Defaults to "ACCEPT_ORIGINAL_SERVER"]

String redirect_policy - A string representing this client’s redirect policy. Acceptable values are listed below. [Optional - Defaults to "Normal"]

                    • "NEVER" - never allow redirects
                    • "ALWAYS" - allow redirects,
                    • "NORMAL" - allows redirects, except those that would downgrade to insecure addresses (i.e., HTTPS redirecting to HTTP).

Callable customizer - A reference to a callable function. This function will be called with one argument (an instance of HttpClient.Builder). The function should operate on the builder class and allows for arbitrary customization of the created HTTP client. [Optional - Defaults to None]

  • Returns

JythonHttpClient  -  An object wrapped around an instance of Java's HttpClient class. The client object has methods that can be called against a website to get or send information through the web. See the panel below for more details.

  • Scope

Gateway, Vision Client, Perspective Session

JythonHttpClient

Once a JythonHttpClient object has been created, HTTP calls can be made with the build in methods detailed below. The various methods available on this object can be split under different categories.

JythonHttpClient Methods

 Methods

This section details synchronous methods. Each method in this section returns a Response object.

Methods

The following methods return a Response object. Parameters for these functions are documented below.

MethodDescriptionReturn type
.get()Sends an HTTP GET call, blocking for a responseResponse
.getAsync()Sends an HTTP GET call without blocking.Promise
.post()Sends an HTTP POST call, blocking for a responseResponse
.postAsync()Sends an HTTP POST call without blocking. Promise
.put()Sends an HTTP PUT call, blocking for a responseResponse
.putAsync()Sends an HTTP PUT call without blocking. Promise
.delete()Sends an HTTP DELETE call, blocking for a responseResponse
.deleteAsync()Sends an HTTP DELETE call without blocking. Promise
.patch()Sends an HTTP PATCH call, blocking for a responseResponse
.patchAsync()Sends an HTTP PATCH call without blocking. Promise
.head()Sends an HTTP HEAD call, blocking for a response.Response
.headAsync()Sends an HTTP HEAD call without blocking. Promise
.options()Sends a blocking HTTP OPTIONS request.Response
.optionsAsync()Sends a non-blocking HTTP OPTIONS request.Promise
.trace()Sends an HTTP TRACE call, blocking for a response.Response
.traceAsync()Sends an HTTP TRACE call, without blocking for a response. Promise
.request()Sends an HTTP request, with the verb being dictated by the method parameter. Use this method in cases where non-standard verb is required, and you need the call to block.Response
.requestAsync()Sends an HTTP request, with the verb being dictated by the method parameter. Use this method in cases where non-standard verb is required, and you do not want the request to block. Promise
.getJavaClient()Returns the underlying Java HTTPClient HTTPClient
.getCookieManager()Returns a CookieManager, which can be used to override the cookie storage policy on the JythonHttpClient.CookieManager


Parameters

Parameters in this section can be used by any of the methods above. Exceptions to this rule will be defined on each parameter.

String url - The URL to connect to. [Required]

String method - The method to use in the request. [Required - used by .request() and .requestAsync() only]

String or Dictionary parameters - Parameters to append to the URL. [Optional - Defaults to None]

          • If supplied as a string, will be directly appended to the URL.
          • If supplied as a dictionary, key/value pairs will be automatically URL encoded.

String or Dictionary or byte[] - Data to send in the request. [Optional - Defaults to None]

            • String data will be sent with a Context-Type of "text/plain; charset=UTF-8", unless the Content-Type header was already specified
            • Dictionary data will be automatically encoded into JSON. The Content-Type header will be set to "application/json;charset=UTF-8" unless the Content-Type header was already specified.
            • Byte arrays will be sent directly, and set the Content-Type header to application/octet-stream unless the Content-Type header was already specified.

String file - The path to a file relative to the HTTP client. If specified, and the path is valid, will directly send the data in the file. The file attribute overrides any value set in data; only the file’s data will be sent.[Optional - Defaults to None]

Dictionary headers - A dictionary of headers to add to the request. [Optional - Defaults to None]

String username - Username to add to a Basic Authorization header in the outgoing request. If username is specified, but not password, password is assumed to be an empty string. [Optional - Defaults to None]

String password - Password to add to a Basic Authorization header in the outgoing request. [Optional - Defaults to None]

Integer timeout - Timeout for this request, in milliseconds. [Optional - Defaults to 60000]

JythonHttpClient Attributes

 Click here to expand...

This section documents available attributes on the JythonHttpClient object, as well as getter methods for those attributes.

AttributeDescriptionReturn Type

.javaClient

Returns the underlying Java HTTPClient.

HTTPClient

.cookieManager


Returns a CookieManager, which can be used to override the cookie storage policy on the JythonHttpClient.

Setting the cookie policy is easiest on the initial system.net.httpClient call, but the policy on the CookieManager can be overriden with a call to the built-in setCookiePolicy method. Policies are defined under the Java CookiePolicy interface. A usage example is demonstrated below.

CookieManager
CookieManager

Once a JythonHttpClient object has been created, HTTP calls can be made with the build in methods detailed below. The various methods available on this object can be split under different categories.

CookieManager Methods

 Methods

This section details methods on the CookieManager. Setting the cookie policy is easiest on the initial system.net.httpClient call, but the policy on the CookieManager can be overriden with a call to the built-in setCookiePolicy method. Policies are defined under the Java CookiePolicy interface.

Methods

MethodDescriptionReturn type
.getJavaClient()Returns the underlying Java HTTPClient.HTTPClient
.getCookieManager()Sends an HTTP GET call, blocking for a responseCookiePolicy
.setCookiePolicy(policy)Sets the CookiePolicy. See the Java CookiePolicy interface for more information.None
from java.net import CookiePolicy

client = system.net.httpClient()
manager = client.getCookieManager()
manager.setCookiePolicy(CookiePolicy.ACCEPT_NONE)

CookieManager Attributes

 Click here to expand...

This section documents available attributes on the CookieManager object, as well as getter methods for those attributes.

AttributeDescriptionReturn Type

.javaClient

Returns the underlying Java HTTPClient

HTTPClient

.cookieManager


Returns a CookieManager, which can be used to override the cookie storage policy on the JythonHttpClient.

Setting the cookie policy is easiest on the initial system.net.httpClient call, but the policy on the CookieManager can be overriden with a call to the built-in setCookiePolicy method. Policies are defined under the Java CookiePolicy interface. A usage example is demonstrated below.

from java.net import CookiePolicy

client = system.net.httpClient()
manager = client.getCookieManager()
manager.setCookiePolicy(CookiePolicy.ACCEPT_NONE)
CookieManager
Response Object

This section documents the Response object, generally returned by the blocking methods returned by the JythonHttpClient object. This object is simply a wrapper for Java's HTTPResponse object.

Response Methods

 Methods

This section details methods on the Response object.

Methods

MethodDescriptionReturn type
.getBody()Returns the response content directly.Byte Array
.getJson( [encoding] )Sends an HTTP GET call without blocking.Promise
.post()Sends an HTTP POST call, blocking for a responseResponse

Response Attributes

 Click here to expand...

This section documents available attributes on the Response object, as well as getter methods for those attributes.

AttributeDescriptionReturn Type

.javaClient

.getJavaClient()

Returns the underlying Java HTTPClient

HTTPClient

.cookieManager

.getCookieManager()

Returns a CookieManager, which can be used to override the cookie storage policy on the JythonHttpClient.

Setting the cookie policy is easiest on the initial system.net.httpClient call, but the policy on the CookieManager can be overriden with a call to the built-in setCookiePolicy method. Policies are defined under the Java CookiePolicy interface. A usage example is demonstrated below.

from java.net import CookiePolicy

client = system.net.httpClient()
manager = client.getCookieManager()
manager.setCookiePolicy(CookiePolicy.ACCEPT_NONE)
CookieManager
Promise Object

This section documents the Promise object, generally returned by the non-blocking methods returned by the JythonHttpClient object. This object is simply a wrapper for Java's CompletableFuture object that returns some type <T>.

Promise Methods

 Methods

This section details methods on the Response object.

Methods

The following methods return a Response object.

MethodDescriptionReturn type
.get()Sends an HTTP GET call, blocking for a responseResponse
.getAsync()Sends an HTTP GET call without blocking.Promise
.post()Sends an HTTP POST call, blocking for a responseResponse

Promise Attributes

 Click here to expand...

This section documents available attributes on the Response object, as well as getter methods for those attributes.

AttributeDescriptionReturn Type

.javaClient

.getJavaClient()

Returns the underlying Java HTTPClient

HTTPClient

.cookieManager

.getCookieManager()

Returns a CookieManager, which can be used to override the cookie storage policy on the JythonHttpClient.

Setting the cookie policy is easiest on the initial system.net.httpClient call, but the policy on the CookieManager can be overriden with a call to the built-in setCookiePolicy method. Policies are defined under the Java CookiePolicy interface. A usage example is demonstrated below.

from java.net import CookiePolicy

client = system.net.httpClient()
manager = client.getCookieManager()
manager.setCookiePolicy(CookiePolicy.ACCEPT_NONE)
CookieManager
RequestWrapper Object

This section documents the RequestWrapper object, which is simply a wrapper around Java's HTTPRequest object.

RequestWrapper Methods

 Methods

This section details methods on the Response object.

Methods

The following methods return a Response object.

MethodDescriptionReturn type
.get()Sends an HTTP GET call, blocking for a responseResponse
.getAsync()Sends an HTTP GET call without blocking.Promise
.post()Sends an HTTP POST call, blocking for a responseResponse

RequestWrapper Attributes

 Click here to expand...

This section documents available attributes on the RequestWrapper object, as well as getter methods for those attributes.

AttributeDescriptionReturn Type

.javaClient

.getJavaClient()

Returns the underlying Java HTTPClient

HTTPClient

.cookieManager

.getCookieManager()

Returns a CookieManager, which can be used to override the cookie storage policy on the JythonHttpClient.

Setting the cookie policy is easiest on the initial system.net.httpClient call, but the policy on the CookieManager can be overriden with a call to the built-in setCookiePolicy method. Policies are defined under the Java CookiePolicy interface. A usage example is demonstrated below.

from java.net import CookiePolicy

client = system.net.httpClient()
manager = client.getCookieManager()
manager.setCookiePolicy(CookiePolicy.ACCEPT_NONE)
CookieManager

Code Examples
Code Snippet
 
Code Snippet
 
  • No labels