Sample code for 30+ languages & platforms
DataFlex

HTTP GET with utf-8 URL Encoded Query Params

See more HTTP Examples

Demonstrates how to build URLs where query param values can be either URL encoded from the utf-8 representation, or from another charset such as windows-1252.

Note: This example uses the new DecodeAndAppend method added in Chilkat v9.5.0.87.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    String sNameWindows1252UrlEncoded
    Handle hoSb1
    Handle hoHttp
    Handle hoSbUrl
    String sResponseBody
    String sTemp1

    Move False To iSuccess

    // We have the string "MÆRSK".

    // This is the URL encoding of the windows-1252 representation.
    Move "M%C6RSK" To sNameWindows1252UrlEncoded

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSb1
    If (Not(IsComObjectCreated(hoSb1))) Begin
        Send CreateComObject of hoSb1
    End
    Get ComDecodeAndAppend Of hoSb1 sNameWindows1252UrlEncoded "url" "windows-1252" To iSuccess

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End

    // Here's how to send an HTTP GET where the param is the utf-8 representation that is URL encoded.
    // For example:  https://www.chilkatsoft.com/something?name=M%C3%A6RSK

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbUrl
    If (Not(IsComObjectCreated(hoSbUrl))) Begin
        Send CreateComObject of hoSbUrl
    End

    Get ComAppend Of hoSbUrl "https://www.chilkatsoft.com/something?name=" To iSuccess
    Get ComGetEncoded Of hoSb1 "url" "utf-8" To sTemp1
    Get ComAppend Of hoSbUrl sTemp1 To iSuccess
    Get ComGetAsString Of hoSbUrl To sTemp1
    Showln sTemp1

    Get ComGetAsString Of hoSbUrl To sTemp1
    Get ComQuickGetStr Of hoHttp sTemp1 To sResponseBody

    // Here's how to send an HTTP GET where the param is the windows-1252 representation that is URL encoded.
    // For example:  https://www.chilkatsoft.com/something?name=M%E6RSK

    Send ComClear To hoSbUrl
    Get ComAppend Of hoSbUrl "https://www.chilkatsoft.com/something?name=" To iSuccess
    Get ComGetEncoded Of hoSb1 "url" "windows-1252" To sTemp1
    Get ComAppend Of hoSbUrl sTemp1 To iSuccess
    Get ComGetAsString Of hoSbUrl To sTemp1
    Showln sTemp1

    Get ComGetAsString Of hoSbUrl To sTemp1
    Get ComQuickGetStr Of hoHttp sTemp1 To sResponseBody


End_Procedure