Show / Hide Table of Contents

    Web Wrapper

    A wrapper for the HttpClient.

    This codeunit simplifies the use of the HttpClient and related features.

    When using the CallHttp* functions, by default, an error will be thrown if the request failed due to an underlying issue such as network connectivity, DNS failure, server certificate validation or timeout (all errors thrown by HttpClient.Send()).

    If you want to handle the error in your own code, you can call SetSilentError(true) before the call. (see examples)

    The responsibility for checking that the response status code is the expected one lies with the caller to these functions.

    Object Definition

    Object TypeCodeunit
    Object ID70327101
    Object NameQWETB Web Wrapper

    Procedures

    Name Description
    AddContentHeader(Text; SecretText) Sets a content header that will be set on the WebRequest Content before HTTP call. Note that not all methods allows content and content headers.
    AddContentHeader(Text; Text) Sets a content header that will be set on the WebRequest Content before HTTP call. Note that not all methods allows content and content headers.
    AddRequestHeader(Text; SecretText) Sets a request header that will be set on the WebRequest before HTTP call.
    AddRequestHeader(Text; Text) Sets a request header that will be set on the WebRequest before HTTP call.
    CallHttpDelete(Text): Boolean Performs a HTTP DELETE call.
    CallHttpGet(Text; Codeunit "QWETB Temp Blob"): Boolean Performs a HTTP GET call.
    CallHttpGet(Text; Codeunit "QWETB Temp Blob"; Codeunit "QWETB Temp Blob"): Boolean Performs a HTTP GET call.
    CallHttpGet(Text; Codeunit "QWETB XML Reader"; Text): Boolean Performs a HTTP GET call.
    CallHttpGet(Text; XmlDocument): Boolean Performs a HTTP GET call.
    CallHttpHead(Text): Boolean Performs a HTTP HEAD call.
    CallHttpPatch(Text; Codeunit "QWETB Temp Blob"; Codeunit "QWETB Temp Blob"): Boolean Performs a HTTP PATCH call.
    CallHttpPost(Text; Codeunit "QWETB Temp Blob"; Codeunit "QWETB Temp Blob"): Boolean Performs a HTTP POST call.
    CallHttpPut(Text): Boolean Performs a HTTP PUT call.
    CallHttpPut(Text; Codeunit "QWETB Temp Blob"; Codeunit "QWETB Temp Blob"): Boolean Performs a HTTP PUT call.
    GetLastErrorCode(): Text Returns the HTTP Status Code from the HttpClient response if the last call failed.
    GetLastErrorMessage(): Text Returns the error message if last call failed. This is used together with the SetSilentError() property.
    GetLastIsSuccessStatusCode(): Boolean Returns if the last HTTP Status Code was a Success (StatusCode was in the range 200-299).
    GetLastReasonPhrase(): Text Gets the reason phrase of the last call, which typically is sent by servers together with the status code.
    GetLastStatusCode(): Integer Returns the HTTP Status Code of the last call.
    GetResponseContentHeaders(): HttpHeaders Returns any content headers in the response received in the last call.
    GetResponseHeaders(): HttpHeaders Returns any response headers received in the last call.
    HttpFileExists(Text): Boolean Checks if a file or url exists. This is performed by doing a HEAD call to the provided URL.
    SetBearerToken(SecretText) Sets a bearer token to be used with bearer authentication. If set, a Bearer Authorization header will be added to the request.
    SetDebugMode(Boolean) Used to troubleshoot HTTP calls.
    SetMaskDebugResponse(Boolean) Sets that the response should be masked if the debug flag to show the response is activated.
    SetPassword(SecretText) Sets a password to be used with basic authentication.
    SetSilentError(Boolean) Sets if HTTP errors should be thrown or caught.
    SetTimeout(Integer) Sets the timeout of the HTTP call in milliseconds.
    SetTimeout(Integer; Boolean) Sets the timeout of the HTTP call in milliseconds.
    SetUseServerCertificateValidation(Boolean) Sets if the server certificate should be validated when doing HTTPS calls.
    SetUserName(Text) Sets a username to be used with basic authentication. If set, a Basic Authorization header will be added to the request.

    Deprecated Procedures

    Name Description
    CallHttpGet(Text; Record "QWETB tTempBlob" temporary): Boolean Performs a HTTP GET call.
    CallHttpGet(Text; Record "QWETB tTempBlob" temporary; Record "QWETB tTempBlob" temporary): Boolean Performs a HTTP GET call.
    CallHttpPatch(Text; Record "QWETB tTempBlob" temporary; Record "QWETB tTempBlob" temporary): Boolean Performs a HTTP PATCH call.
    CallHttpPost(Text; Record "QWETB tTempBlob" temporary; Record "QWETB tTempBlob" temporary): Boolean Performs a HTTP POST call.
    CallHttpPut(Text; Record "QWETB tTempBlob" temporary; Record "QWETB tTempBlob" temporary): Boolean Performs a HTTP PUT call.
    SetBearerToken(Text) Sets a bearer token to be used with bearer authentication. If set, a Bearer Authorization header will be added to the request.
    SetPassword(Text) Sets a password to be used with basic authentication.

    Events

    Name Description
    OnBeforeHttpClientSend(HttpRequestMessage; HttpContent; HttpHeaders; HttpHeaders; Integer; Text; Boolean; Text; Text; Boolean) This event is used for tests and is raised just before the HttpClient.Send call.

    Example

    Below are two examples, with or without silent error handling.

    With silent error handling

    WebWrapper.SetSilentError(true);
    
    If not WebWrapper.CallHttpGet(Url, Response) then
      HandleError(WebWrapper); // Use GetLastErrorText(), GetLastReasonPhrase() or GetLastErrorCode() to get what went wrong
    
    HandleHttpStatus(WebWrapper, Response); // Use GetLastStatusCode() or GetLastReasonPhrase() to get the server response
    

    With no silent error handling

    WebWrapper.CallHttpGet(Url, Response); // An Error will be thrown if the call fails
    
    HandleHttpStatus(WebWrapper, Response); // Use GetLastStatusCode() or GetLastReasonPhrase() to get the server response
    

    This documentation is generated from Smart Toolbox v27.0

    Back to top Copyright © 2020 SmartApps
    Generated by DocFX