NetXDuo WEB HTTP Client POST message

Carl Lee 0 Reputation points
2023-07-27T01:14:28.7133333+00:00

Dear all,

I am going to use the NETDuo library and studying the sample code about the NetXDuo WEB Client to PUT/POST message to the HTTP server. The URL of the HTTP server is like:

                              aaa.bbb.com/api/admin/anchor

I still do not understand how to feed the parameters above to the subroutine nx_web_http_client_post_start() in order to start the post.

 status = nx_web_http_client_post_start(&my_client, IP_ADDRESS(0, 0, 0, 0),
        NX_WEB_HTTP_SERVER_PORT, "/api/admin/anchor", "aaa.bbb.com",  "apple", "123456", 103, 50);

Please advice

Thanks,

Carl

Azure RTOS
Azure RTOS
An Azure embedded development suite including a small but powerful operating system for resource-constrained devices.
331 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. LeelaRajeshSayana-MSFT 14,676 Reputation points Microsoft Employee
    2023-07-27T13:19:20.02+00:00

    Hi @Carl Lee Greetings! Welcome to Microsoft Q&A forum. Thank you for posting this question here.

    I would like to make a note that the service nx_web_http_client_post_start has been deprecated. It is highly recommended to use *nx_web_http_client_post_start_extended as an alternative approach to achieve the same. The Post request accepts the following parameters.

    UINT nx_web_http_client_post_start_extended(
        NX_WEB_HTTP_CLIENT *client_ptr,
        NXD_ADDRESS ip_address,
        UINT server_port,
        CHAR *resource,
        UINT resource_length,
        CHAR *host,
        UINT host_length,
        CHAR *username,
        UINT username_length,
        CHAR *password,
        UINT password_length,
        ULONG total_bytes,
        ULONG wait_option);
    

    Here is a description on the input parameters of the method.

    • client_ptr: Pointer to HTTP Client control block.
    • ip_address: IP address of the HTTP Server.
    • server_port: TCP port on the remote HTTP Server.
    • resource: Pointer to URL string for requested resource.
    • resource_length: String length of requested resource.
    • host: Null-terminated string of the server’s domain name. This string is transmitted in the HTTP Host header field. The host string cannot be NULL.
    • host_length: String length of host.
    • username: Pointer to optional user name for authentication.
    • username_length: String length of user name for authentication.
    • password: Pointer to optional password for authentication.
    • password_length: String length of password for authentication.
    • total_bytes: Total bytes of resource being sent. Note that the combined length of all packets sent via subsequent calls to nx_web_http_client_put_packet must equal this value.
    • wait_option: Defines how long the service will wait for the HTTP Client get start request. The wait options are defined as follows:
      • timeout value (0x00000001 through 0xFFFFFFFE) Selecting a numeric value (0x1-0xFFFFFFFE) specifies the maximum number of timer-ticks to stay suspended while waiting for the HTTP Server response.
        • NX_WAIT_FOREVER (0xFFFFFFFF) Selecting NX_WAIT_FOREVER causes the calling thread to suspend indefinitely until the HTTP Server responds to the request.

    Here is an example on how to use this method.

    /* Connect to a remote HTTP server. */
    server_ip_addr.nxd_ip_version = NX_IP_VERSION_V4;
    server_ip_addr.nxd_ip_address.v4 = IP_ADDRESS(1,2,3,5);
    
    /* Start an HTTP POST to post the 20-byte resource "/TEST.HTM" to the HTTP Server
        at IP address 1.2.3.5. */
    status = nx_web_http_client_post_start_extended(&my_client,
        &server_ip_addr, NX_WEB_HTTPS_SERVER_PORT,
        "/TEST.HTM", sizeof("/TEST.HTM") – 1,
        "host.com", sizeof("host.com") – 1,
        "myname", sizeof("myname") – 1,
        "mypassword", sizeof("mypassword") – 1, 20,
        NX_WAIT_FOREVER);
    
    /* If status is NX_SUCCESS, the POST operation for TEST.HTM has successfully been
        started. */
    

    Please find the reference to the official documentation on nx_web_http_client_post_start_extended method for more details. Hope this helps! Please let us know if you have any additional questions on this.


    If the response helped, please do click Accept Answer and Yes for the answer provided. Doing so would help other community members with similar issue identify the solution. I highly appreciate your contribution to the community.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.