zs39 opened a new pull request, #3304:
URL: https://github.com/apache/nuttx-apps/pull/3304

   ## Summary
   
   Add netlib_check_httpconnectivity() to verify HTTP service connectivity by 
sending GET request and validating status code.
   
   ## Impact
   
   The new features have no impact.
   
   ## Testing
   
   Use the demo below for testing.
   ```
   /****************************************************************************
    * apps/examples/hello/hello_main.c
    *
    * SPDX-License-Identifier: Apache-2.0
    *
    * Licensed to the Apache Software Foundation (ASF) under one or more
    * contributor license agreements.  See the NOTICE file distributed with
    * this work for additional information regarding copyright ownership.  The
    * ASF licenses this file to you under the Apache License, Version 2.0 (the
    * "License"); you may not use this file except in compliance with the
    * License.  You may obtain a copy of the License at
    *
    *   http://www.apache.org/licenses/LICENSE-2.0
    *
    * Unless required by applicable law or agreed to in writing, software
    * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
    * License for the specific language governing permissions and limitations
    * under the License.
    *
    
****************************************************************************/
   
   /****************************************************************************
    * Included Files
    
****************************************************************************/
   
   #include <nuttx/config.h>
   #include <stdio.h>
   #include <string.h>
   #include <errno.h>
   
   #include <netutils/netlib.h>
   
   /****************************************************************************
    * Public Functions
    
****************************************************************************/
   
   /****************************************************************************
    * hello_main
    
****************************************************************************/
   
   int main(int argc, FAR char *argv[])
   {
     const char *host = "www.example.com";
     const char *path = "";
     int port = 80;
     int expect_code = 200;
     int ret;
   
     printf("Hello, World!!\n");
     printf("\n");
     printf("========================================\n");
     printf("HTTP Connectivity Test\n");
     printf("========================================\n");
     printf("\n");
   
     printf("Testing: http://%s:%d/%s\n";, host, port, path);
     printf("Expected HTTP status code: %d\n", expect_code);
     printf("\n");
   
     printf("Checking HTTP connectivity...\n");
     ret = netlib_check_httpconnectivity(host, path, port, expect_code);
   
     printf("\n");
     printf("========================================\n");
     if (ret == 0)
       {
         printf("SUCCESS: HTTP connectivity check passed!\n");
         printf("Server returned expected status code: %d\n", expect_code);
       }
     else
       {
         printf("FAILED: HTTP connectivity check failed!\n");
         if (ret < 0)
           {
             if (ret > -1000)
               {
                 printf("HTTP Status Code: %d (expected %d)\n",
                        -ret, expect_code);
               }
             else
               {
                 printf("Error: %s\n", strerror(-ret));
               }
           }
       }
     printf("========================================\n");
   
     return (ret == 0) ? 0 : 1;
   }
   
   ```
   The results are as follows
   ```
   nsh> hello
   Hello, World!!
   
   ========================================
   HTTP Connectivity Test
   ========================================
   
   Testing: http://www.example.com:80/
   Expected HTTP status code: 200
   
   Checking HTTP connectivity...
   
   ========================================
   SUCCESS: HTTP connectivity check passed!
   Server returned expected status code: 200
   ========================================
   ```
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to