Skip to content

Commit

Permalink
update:csdk http增加PUT和DELETE
Browse files Browse the repository at this point in the history
  • Loading branch information
allewalker committed Apr 28, 2024
1 parent d9fef07 commit 2102d97
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
4 changes: 2 additions & 2 deletions components/network/libhttp/luat_http.h
Expand Up @@ -210,12 +210,12 @@ int luat_http_client_set_user_head(luat_http_ctrl_t *http_ctrl, const char *name
*
* @param http_ctrl 客户端
* @param url http请求完整的url,如果有转义字符需要提前转义好
* @param is_post 是否是post请求
* @param type 请求类型,0 get 1 post 2 put 3 delete
* @param ipv6 是否存在IPV6的服务器
* @param data_mode 大数据模式,接收数据超过1KB的时候,必须开启。开启后请求头里自动加入"Accept: application/octet-stream\r\n"
* @return 成功返回0,其他值失败
*/
int luat_http_client_start(luat_http_ctrl_t *http_ctrl, const char *url, uint8_t is_post, uint8_t ipv6, uint8_t continue_mode);
int luat_http_client_start(luat_http_ctrl_t *http_ctrl, const char *url, uint8_t type, uint8_t ipv6, uint8_t continue_mode);
/**
* @brief 停止当前的http请求,调用后不再有http回调了
*
Expand Down
24 changes: 19 additions & 5 deletions components/network/libhttp/luat_http_client.c
Expand Up @@ -1043,7 +1043,7 @@ int luat_http_client_post_body(luat_http_ctrl_t *http_ctrl, void *data, uint32_t
http_send(http_ctrl, data, len);
return 0;
}
int luat_http_client_start(luat_http_ctrl_t *http_ctrl, const char *url, uint8_t is_post, uint8_t ipv6, uint8_t data_mode)
int luat_http_client_start(luat_http_ctrl_t *http_ctrl, const char *url, uint8_t type, uint8_t ipv6, uint8_t data_mode)
{
if (!http_ctrl) return -ERROR_PARAM_INVALID;
if (http_ctrl->state)
Expand All @@ -1054,7 +1054,19 @@ int luat_http_client_start(luat_http_ctrl_t *http_ctrl, const char *url, uint8_t
}
return -ERROR_PERMISSION_DENIED;
}
http_ctrl->is_post = is_post;
switch(type)
{
case 0:
case 3:
http_ctrl->is_post = 0;
break;
case 1:
case 2:
http_ctrl->is_post = 1;
break;
default:
return -ERROR_PARAM_INVALID;
}
http_ctrl->data_mode = data_mode;
http_ctrl->retry_cnt = 0;
http_ctrl->total_len = 0;
Expand Down Expand Up @@ -1149,8 +1161,10 @@ int luat_http_client_start(luat_http_ctrl_t *http_ctrl, const char *url, uint8_t
return -ERROR_NO_MEMORY;
}


snprintf_((char*)http_ctrl->request_line, 8192, "%s %s HTTP/1.1\r\n", is_post?"POST":"GET", tmpuri);
const char *me[4] = {
"GET","POST","PUT","DELETE"
};
snprintf_((char*)http_ctrl->request_line, 8192, "%s %s HTTP/1.1\r\n", me[type], tmpuri);

if (http_ctrl->timeout)
{
Expand Down Expand Up @@ -1300,4 +1314,4 @@ int luat_http_client_start(luat_http_ctrl_t* http_ctrl) {
}
return 0;
}
#endif
#endif

0 comments on commit 2102d97

Please sign in to comment.