NuMaker Ethernet TCP

Revision:
17:e5e8673e25ae
Parent:
16:5df36a9f0f60
Child:
18:65dbb1786dc4
--- a/main.cpp	Tue Oct 16 15:00:03 2018 +0800
+++ b/main.cpp	Fri Jul 19 16:10:23 2019 +0800
@@ -7,16 +7,16 @@
 namespace {
     // Test connection information
 #ifndef LOCAL_LAN
-const char *HTTP_SERVER_NAME = "os.mbed.com";
+const char *HTTP_SERVER_NAME = "www.ifconfig.io"; 
 #else
 const char *HTTP_SERVER_NAME = "pt22_winserver2.nuvoton.com";
 #endif
 
 #ifndef LOCAL_LAN
-const char *HTTP_SERVER_FILE_PATH = "/media/uploads/mbed_official/hello.txt";
+const char *HTTP_SERVER_FILE_PATH = "/method";
 const int HTTP_SERVER_PORT = 80;
 #else
-const char *HTTP_SERVER_FILE_PATH = "/examples/arm_mbed/hello.txt";
+const char *HTTP_SERVER_FILE_PATH = "/examples/arm_mbed/method.txt";
 const int HTTP_SERVER_PORT = 8080;
 #endif
 
@@ -28,7 +28,7 @@
 
     // Test related data
     const char *HTTP_OK_STR = "200 OK";
-    const char *HTTP_HELLO_STR = "Hello world!";
+    const char *HTTP_EXPECT_STR = "GET";
 
     // Test buffers
     char buffer[RECV_BUFFER_SIZE] = {0};
@@ -60,11 +60,21 @@
         printf("HTTP: Connected to %s:%d\r\n", HTTP_SERVER_NAME, HTTP_SERVER_PORT);
 
         // We are constructing GET command like this:
-        // GET http://developer.mbed.org/media/uploads/mbed_official/hello.txt HTTP/1.0\n\n
+#ifndef USE_HTTP_1_1
+        // GET http://www.ifconfig.io/method HTTP/1.0\n\n
         strcpy(buffer, "GET http://");
         strcat(buffer, HTTP_SERVER_NAME);
         strcat(buffer, HTTP_SERVER_FILE_PATH);
-        strcat(buffer, "HTTP/1.0\n\n");
+        strcat(buffer, " HTTP/1.0\n\n");
+#else
+       // GET /method HTTP/1.1\r\nHost: ifconfig.io\r\nConnection: close\r\n\r\n"
+        strcpy(buffer, "GET ");
+        strcat(buffer, HTTP_SERVER_FILE_PATH);   
+        strcat(buffer, " HTTP/1.1\r\nHost: ");
+        strcat(buffer, HTTP_SERVER_NAME);
+        strcat(buffer, "\r\nConnection: close\r\n\r\n");
+#endif
+        
         // Send GET command
         sock.send(buffer, strlen(buffer));
 
@@ -74,15 +84,15 @@
 
         // Find 200 OK HTTP status in reply
         bool found_200_ok = find_substring(buffer, buffer + ret, HTTP_OK_STR, HTTP_OK_STR + strlen(HTTP_OK_STR));
-        // Find "Hello World!" string in reply
-        bool found_hello = find_substring(buffer, buffer + ret, HTTP_HELLO_STR, HTTP_HELLO_STR + strlen(HTTP_HELLO_STR));
+        // Find "deny" string in reply
+        bool found_expect = find_substring(buffer, buffer + ret, HTTP_EXPECT_STR, HTTP_EXPECT_STR + strlen(HTTP_EXPECT_STR));
 
         if (!found_200_ok) result = false;
-        if (!found_hello) result = false;
+        if (!found_expect) result = false;
 
         printf("HTTP: Received %d chars from server\r\n", ret);
         printf("HTTP: Received 200 OK status ... %s\r\n", found_200_ok ? "[OK]" : "[FAIL]");
-        printf("HTTP: Received '%s' status ... %s\r\n", HTTP_HELLO_STR, found_hello ? "[OK]" : "[FAIL]");
+        printf("HTTP: Received '%s' status ... %s\r\n", HTTP_EXPECT_STR, found_expect ? "[OK]" : "[FAIL]");
         printf("HTTP: Received massage:\r\n\r\n");
         printf("%s", buffer);
     }