完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我使用的IDF-4.4.2,使用file_server例程作为http server服务器。然后使用esp_http_client向file_server上传文件,使用的POST上传文件,上报时,报了一个405的警告。
Code: Select all I (865851) esp_netif_lwip: DHCP server assigned IP to a station, IP is: 192.168.4.3 W (867401) wifi: I (867471) file_server: Sending file : /config.ini (206 bytes)... I (867471) file_server: File sending complete I (868061) file_server: Receiving file : /text.log... I (868061) file_server: Remaining size : 19 I (868081) file_server: File reception complete W (868361) httpd_uri: httpd_uri: Method '3' not allowed for URI '/' W (868361) httpd_txrx: httpd_resp_send_err: 405 Method Not Allowed - Request method for this URI is not handled by server file_server例程中配置了POST的方法,还出现了警告,应该怎么解决? Code: Select all /* URI handler for uploading files to server */ httpd_uri_t file_upload = { .uri = "/upload/*", // Match all URIs of type /upload/path/to/file .method = HTTP_POST, .handler = upload_post_handler, .user_ctx = server_data // Pass server data as context }; httpd_register_uri_handler(server, &file_upload); esp_http_client端就用了GET和POST两种 Code: Select all char local_response_buffer[MAX_HTTP_OUTPUT_BUFFER] = {0}; /** * NOTE: All the configuration parameters for http_client must be spefied either in URL or as host and path parameters. * If host and path parameters are not set, query parameter will be ignored. In such cases, * query parameter should be specified in URL. * * If URL as well as host and path parameters are specified, values of host and path will be considered. */ esp_http_client_config_t config = { // .host = "httpbin.org", // .path = "/get", // .query = "esp", .url = "http://192.168.4.1/config.ini", .event_handler = _http_event_handler, .user_data = local_response_buffer, // Pass address of local buffer to get response //.disable_auto_redirect = true, }; esp_http_client_handle_t client = esp_http_client_init(&config); // GET esp_err_t err = esp_http_client_perform(client); if (err == ESP_OK) { ESP_LOGI(TAG, "HTTP GET Status = %d, content_length = %d", esp_http_client_get_status_code(client), esp_http_client_get_content_length(client)); } else { ESP_LOGE(TAG, "HTTP GET request failed: %s", esp_err_to_name(err)); } ESP_LOG_BUFFER_HEX(TAG, local_response_buffer, strlen(local_response_buffer)); // POST const char *post_data = "{"field1":"value1"}"; esp_http_client_set_url(client, "http://192.168.4.1/upload/text.log"); esp_http_client_set_method(client, HTTP_METHOD_POST); esp_http_client_set_header(client, "Content-Type", "application/json"); esp_http_client_set_post_field(client, post_data, strlen(post_data)); err = esp_http_client_perform(client); if (err == ESP_OK) { ESP_LOGI(TAG, "HTTP POST Status = %d, content_length = %d", esp_http_client_get_status_code(client), esp_http_client_get_content_length(client)); } else { ESP_LOGE(TAG, "HTTP POST request failed: %s", esp_err_to_name(err)); } |
|
相关推荐
|
|
只有小组成员才能发言,加入小组>>
1138 浏览 1 评论
576浏览 6评论
477浏览 5评论
有没有办法在不使用混杂模式的情况下实现Wifi驱动程序接收缓冲区访问中断呢?
461浏览 5评论
462浏览 4评论
437浏览 4评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-22 14:51 , Processed in 0.770320 second(s), Total 74, Slave 57 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号