http使用post方法
authorhcj <1224667075@qq.com>
Tue, 23 Apr 2024 02:28:26 +0000 (10:28 +0800)
committerhcj <1224667075@qq.com>
Tue, 23 Apr 2024 02:28:26 +0000 (10:28 +0800)
code/sdk/open_source/openharmony/third_party/lwip/src/apps/http/http_client.c
code/sdk/open_source/openharmony/third_party/lwip/src/include/lwip/apps/http_client.h

index 4371c3d..1b57cd3 100644 (file)
     "\r\n"
 #define HTTPC_REQ_11_PROXY_PORT_FORMAT(host, host_port, uri, srv_name) HTTPC_REQ_11_PROXY_PORT, host, host_port, uri, HTTPC_CLIENT_AGENT, srv_name
 
+
+////////////////////////////////////////post报文///////////////////////////////////////////////////
+/* POST request basic */  
+#define HTTPC_REQ_11_POST "POST %s HTTP/1.1\r\n" /* URI */\
+    "User-Agent: %s\r\n" /* User-Agent */ \
+    "Accept: */*\r\n" \
+    "Content-Type: application/x-www-form-urlencoded\r\n" \
+    "Content-Length: %d\r\n" \
+    "Connection: Close\r\n" /* we don't support persistent connections, yet */\
+    "\r\n" \
+    "%s"
+      
+#define HTTPC_REQ_11_FORMAT_POST(uri, arglen, args)  HTTPC_REQ_11_POST, uri, HTTPC_CLIENT_AGENT, arglen, args
+      
+/* POST request with host */
+#define HTTPC_REQ_11_HOST_POST "POST %s HTTP/1.1\r\n" /* URI */\
+    "User-Agent: %s\r\n" /* User-Agent */ \
+    "Accept: */*\r\n" \
+    "Host: %s\r\n" /* server name */ \
+    "Content-Type: application/x-www-form-urlencoded\r\n" \
+    "Content-Length: %d\r\n" \
+    "Connection: Close\r\n" /* we don't support persistent connections, yet */ \
+    "\r\n" \
+    "%s"
+      
+#define HTTPC_REQ_11_HOST_FORMAT_POST(uri, srv_name, arglen, args) HTTPC_REQ_11_HOST, uri, HTTPC_CLIENT_AGENT, srv_name, arglen, args
+
 typedef enum ehttpc_parse_state {
   HTTPC_PARSE_WAIT_FIRST_LINE = 0,
   HTTPC_PARSE_WAIT_HEADERS,
@@ -494,10 +521,22 @@ httpc_create_request_string(const httpc_connection_t *settings, const char* serv
     } else {
       return snprintf(buffer, buffer_size, HTTPC_REQ_11_PROXY_FORMAT(server_name, uri, server_name));
     }
-  } else if (use_host) {
+  }
+  else if (use_host) 
+  {
     LWIP_ASSERT("server_name != NULL", server_name != NULL);
+
+    if (settings->use_post)
+    {
+                 return snprintf(buffer, buffer_size, HTTPC_REQ_11_HOST_FORMAT_POST(uri, server_name, settings->arglen, settings->args));
+         }
     return snprintf(buffer, buffer_size, HTTPC_REQ_11_HOST_FORMAT(uri, server_name));
-  } else {
+  } 
+  else 
+  {
+    if (settings->use_post){
+       return snprintf(buffer, buffer_size, HTTPC_REQ_11_FORMAT_POST(uri, settings->arglen, settings->args));
+    }
     return snprintf(buffer, buffer_size, HTTPC_REQ_11_FORMAT(uri));
   }
 }
index 8a06308..d7dc9f2 100644 (file)
@@ -137,6 +137,13 @@ typedef struct _httpc_connection {
   /* this callback is called after receiving the http headers
      It can abort the connection by returning != ERR_OK */
   httpc_headers_done_fn headers_done_fn;
+
+  //添加post
+  u8_t  use_post;
+  u8_t  arglen;
+  u8_t* args;
+
+
 } httpc_connection_t;
 
 err_t httpc_get_file(const ip_addr_t* server_addr, u16_t port, const char* uri, const httpc_connection_t *settings,