From: hcj <1224667075@qq.com> Date: Tue, 23 Apr 2024 02:28:26 +0000 (+0800) Subject: http使用post方法 X-Git-Tag: release_V1.2.70_20241020_135402~1137^2~5 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=8fe96cef8eac917995b8250174cd014615209ee0;p=mirrors%2FFD230.git http使用post方法 --- diff --git a/code/sdk/open_source/openharmony/third_party/lwip/src/apps/http/http_client.c b/code/sdk/open_source/openharmony/third_party/lwip/src/apps/http/http_client.c index 4371c3d15..1b57cd308 100644 --- a/code/sdk/open_source/openharmony/third_party/lwip/src/apps/http/http_client.c +++ b/code/sdk/open_source/openharmony/third_party/lwip/src/apps/http/http_client.c @@ -124,6 +124,33 @@ "\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)); } } diff --git a/code/sdk/open_source/openharmony/third_party/lwip/src/include/lwip/apps/http_client.h b/code/sdk/open_source/openharmony/third_party/lwip/src/include/lwip/apps/http_client.h index 8a0630833..d7dc9f233 100644 --- a/code/sdk/open_source/openharmony/third_party/lwip/src/include/lwip/apps/http_client.h +++ b/code/sdk/open_source/openharmony/third_party/lwip/src/include/lwip/apps/http_client.h @@ -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,