HSL 2.0 framework
Description of the framework
Public Member Functions |List of all members
hsl20_4_http_client.hsl20_4_http_client.Client Class Reference

All methods of the HTTP client More..

Public Member Functions

def__init__ (self, framework, context_map)
Constructor. More...
defset_url (self, method, url, http_version=1)
Sets the URL to be called. More...
defset_header (self, key, value)
Sets a header. More...
defset_body (self, data, content_type=None)
Set the body. More...
defset_on_data (self, callback)
Specifies a callback method for the response. More...
defset_on_error (self, callback)
Specifies a callback method for errors. More...
defstart_request (self)
Starts HTTP polling. More...

Detailed Description

All methods of the HTTP client

Deprecated:
This class should no longer be used. The example https_client WebRequest shows how it can be replaced by standard Python modules

Used for communication with a remote terminal via HTTP.

Timeouts

The following timeouts, which will disconnect the connection when they occur, must be observed:

class my_demo_module(hsl20_4.BaseModule):
...
def get_demo_page(self):
client = self.FRAMEWORK.create_http_client()
client.set_url("GET" , "http://www.example.net/" )
client.set_on_data(self.on_example_data)
client.start_request()
def on_example_data(self, http_response):
if http_response.get_status_code()==200:
# Evaluate response
Note
The class works asynchronously. None of the methods offered are blocked

Constructor & Destructor Documentation

◆ __init__()

def hsl20_4_http_client.hsl20_4_http_client.Client.__init__ ( self,
framework,
context_map
)

Constructor

Warning
This class should not be instantiated directly

Member Function Documentation

◆ set_body()

def hsl20_4_http_client.hsl20_4_http_client.client.set_body ( self,
data,
content_type = None
)

Set the body

Only needed for e.g. POST and GET. The method also sets the HTTP header "Content-length" based on the data passed under data

Parameters
datastring
Data
content_typestring
Optional, sets in the header the content-type of the data to be transmitted (default: None) Note added to the default value of parameter content_type

◆ set_header()

def hsl20_4_http_client.hsl20_4_http_client.Client.set_header ( self,
key,
value
)

Sets a header

For example: set_header("Content-type", "text/html")
Several headers can be defined

Parameters
keystring
Key of the header
valuestring
Value

◆ set_on_data()

def hsl20_4_http_client.hsl20_4_http_client.client.set_on_data ( self,
callback
)

Specifies a callback method for the response

The method is called when the remote party has completely answered the request or when an error has occurred.

The callback method requires the following parameters:

Parameters
callbackfunction
Callback method

◆ set_on_error()

def hsl20_4_http_client.hsl20_4_http_client.Client.set_on_error ( self,
callback
)

Specifies a callback method for errors

The callback method is called when an error or timeout occurs during communication.

The callback method requires the following parameters:

  • exception exception
    The exception that occurred. Returns None if an unknown error has occurred.
Parameters
callbackfunction
Callback method

◆ set_url()

def hsl20_4_http_client.hsl20_4_http_client.client.set_url ( self,
method,
ancient,
http_version = 1
)

Sets the URL to be called

Parameters
methodstring
Retrieval method to be used for the URL (e.g. GET)
urlstring
URL (e.g. http://www.example.net/)
http_versionint
Optional. HTTP version.
  • 1 => HTTP/1.0 (default)
  • 2 => HTTP/1.1
Note
The transferring URL must be correctly encoded
Exceptions
ValueError
Dispatched when an invalid URL is supplied
ValueError
Dispatched when an invalid HTTP version is submitted

◆ start_request()

def hsl20_4_http_client.hsl20_4_http_client.client.start_request ( self)

Starts HTTP polling

Triggers an exception if not all attributes required for the request are set

Exceptions
AttributeError
Triggers an exception if not all attributes required for the retrieval are set
RuntimeError
Triggers an exception if the host name could not be resolved
RuntimeError
Triggers an exception if the method has already been called

The documentation for this class was generated from the following file: