Code Monkey home page Code Monkey logo

webclient's Introduction

WebClient

Chinese | English

1. Introduction

The WebClient software package is independently developed by RT-Thread and is based on the implementation of the HTTP protocol client. It provides the basic functions of communication between the device and the HTTP Server.

The features of the WebClient software package are as follows:

  • Support IPV4/IPV6 address;
  • Support GET/POST request method;
  • Support file upload and download function;
  • Support HTTPS encrypted transmission;
  • Complete header data addition and processing methods.

For more software package introduction, please refer to Detailed introduction.

1.1 Directory structure

The directory structure of the WebClient software package is as follows:

webclient
├───docs 
│   └───figures                   // Documents use pictures
│   │   api.md                    // API instructions
│   │   introduction.md           // Introduction document
│   │   principle.md              // Implementation principle
│   │   README.md                 // Document structure description
│   │   samples.md                // package sample
│   │   user-guide.md             // Instructions
│   └───version.md                // version
├───inc                           // header file
├───src                           // source file
├───samples                       // sample code
|   |   webclient_get_sample      // GET request sample code
│   └───webclient_post_sample     // POST request sample code
│   LICENSE                       // package license
│   README.md                     // Software package instructions
└───SConscript                    // RT-Thread default build script

1.2 License

The WebClient software package complies with the Apache-2.0 license, see the LICENSE file for details.

1.3 Dependency

2. Get the software package

To use the WebClient software package, you need to select it in the RT-Thread package management. The specific path is as follows:

RT-Thread online packages
    IoT-internet of things --->
         [*] WebClient: A HTTP/HTTPS Client for RT-Thread
         [ ]   Enable debug log output
         [ ]   Enable webclient GET/POST/SHARD samples
         [ ]   Enable file download feature support
               Select TLS mode (Not support)  --->
                   (x) Not support
                   () SAL TLS support
                   () MbedTLS support
               Version (latest) --->

Enable webclient GET/POST samples: add sample code; Select TLS mode: Configure to enable HTTPS support and select the supported mode;

  • Not support: Does not support TLS function;
  • SAL TLS support: Configure the TLS function support in the SAL component, and abstract the TLS operation in the SAL component. Users also need to manually configure the type of TLS software package used (currently only supports the MbedTLS package);
  • MbedTLS support: configure MbedTLS function support; Version: Configure the software package version.

After the configuration is complete, let the RT-Thread package manager automatically update, or use the pkgs --update command to update the package to the BSP.

3. Use WebClient software package

  • For detailed description of the software package, please refer to Package Introduction

  • For detailed sample introduction, please refer to Sample Document

  • How to use from scratch, please refer to User Guide

  • For complete API documentation, please refer to API Manual

  • The working principle of the software package, please refer to Working Principle

  • More Detailed introduction documents are located in the /docs folder, Please check before using the package for development.

4. Matters needing attention

  • When the WebClient software package connects to the HTTPS server, you need to enable the TLS function support in WebClient.
  • After the WebClient software package version update (V1.0.0 -> the current latest version V2.0.0), the function interface and usage process in the software package have changed. If the previous interface is used in the developer code, the latest version interface can be adapted , Or select the V1.0.0 version in the version number configuration, the specific modification method can refer to the software package migration guide.

5. Contact & Thanks

webclient's People

Contributors

aozima avatar armink avatar bernardxiong avatar chichen113 avatar dongly avatar enkiller avatar fanwenl avatar guozhanxin avatar hubertxie avatar junlon2006 avatar lawlieta avatar liu2guang avatar liuduanfei avatar luanxg avatar luhuadong avatar murphyzhao avatar mysterywolf avatar qiyongzhong0 avatar summergift avatar sunxofrtt avatar wendal avatar xiangxistu avatar yangjie11 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

webclient's Issues

https测试找不到mbedtls的部分接口

你好!
 从社区下载的mbedtls和webclient,测试webclient的https功能时,发现打开宏WEBCLIENT_USING_MBED_TLS后,编译找不到tls_client.h文件.
1.这个文件是自定义的吗?
2.另外发现webclient/src/webclient.c中使用的mbedtls的接口:
mbedtls_client_init
mbedtls_client_read
mbedtls_client_write
mbedtls_client_connect
mbedtls_client_context
mbedtls_client_close
都不存在.这些接口也是要自己定义的吗?

麻烦指导一下,谢谢!

wget 导致 hardfault 的问题

msh />wget http://www.rt-thread.com /service/rt-thread.txt
[31145] E/web: connect failed, resolve address error(-1).
[31152] E/web.file: get file failed, wrong response: -1.
msh />wget http://www.rt-thread.com/ service/rt-thread.txt  
[47648] E/web: not support https connect, please enable webclient https configure!
[47657] E/web.file: get file failed, wrong response: -1.
psr: 0x21090000
r00: 0x2dcc2958
r01: 0x0000006d
r02: 0xffffffff
r03: 0x2dcc2940
r04: 0x2000d760
r05: 0x2000d760
r06: 0xdeadbeef
r07: 0x2000e0f8
r08: 0xdeadbeef
r09: 0xdeadbeef
r10: 0xdeadbeef
r11: 0xdeadbeef
r12: 0x200129c8
 lr: 0x0800815b
 pc: 0x08007ec8
hard fault on thread: tshell

thread   pri  status      sp     stack size max used left tick  error
-------- ---  ------- ---------- ----------  ------  ---------- ---
phy       30  suspend 0x000000c0 0x00000400    22%   0x00000002 000
tshell    20  ready   0x00000264 0x00000800    62%   0x0000000a 000
tcpip     10  suspend 0x000000ec 0x00000400    89%   0x0000000e 000
etx       12  suspend 0x000000ac 0x00000400    16%   0x00000010 000
erx       12  suspend 0x000000b4 0x00000400    63%   0x0000000d 000
tidle0    31  ready   0x00000060 0x00000400    13%   0x00000008 000
main      10  suspend 0x00000144 0x00000800    45%   0x00000004 000
bus fault:
SCB_CFSR_BFSR:0x82 PRECISERR SCB->BFAR:2DCC2940

访问主页时,如果路径末尾没有/,访问会失败。

示例

失败的示例

http://www.rt-thread.org
http://www.rt-thread.org:80

成功的示例

http://www.rt-thread.org/
http://www.rt-thread.org:80/

在浏览器上面测试,发现浏览器会自动加上末尾的 /。
如果URL是手动输入或编码,可以要求使用者必须有加/。但在项目中有遇到服务器下发的URL也是不带/的。因此,可以考虑在 webclient中添加这个功能。

webclient软件包选择TLS模式为 MbedTLS support时的问题

[E/web] connect failed, https client connect return: -0x1
webclient POST request failed, response(-6) error.
[E/mbedtls.clnt] verify peer certificate fail....
[E/mbedtls.clnt] verification info: ! The certificate is not correctly signed by the trusted CA
终端显示的错误问题,网上好像还没有解决方案

上传/下载文件函数 能获取的参数太少

1.webclient_post_file()/webclient_get_file()函数中,能否添加header入参,允许外部设定header
2.webclient_post_file()能否返回出一系列数据,比如: 开发者服务器返回的数据 和 http状态码
3.能否提供监控文件传输的进度的接口或者参数
4. 能否提供中断文件传输的接口

webclient_get_position可能出现内存越界

在webclient_send_header
rt_snprintf(session->header->buffer + session->header->length, session->header->size, "\r\n");

第二个参数应该修改为session->header->size - session->header->length

wget使用时http和https问题

你好:
我在使用wget时遇到如下两个问题,麻烦帮忙看看.感激.
1.链接明明是http怎么提示需要enable https configure.
msh />webclient_pull http://www.rt-thread.com /service/rt-thread.txt
[E/web] not support https connect, please enable webclient https configure!
[E/web.file] get file failed, wrong response: -1 (-0xFFFFFFFF).
msh />
2.配置了mebdtls作为加密方式,又出现如下问题.
[E/mbedtls.clnt] verify peer certificate fail....
[E/mbedtls.clnt] verification info: ! The certificate is not correctly signed by the trusted CA
! The certificate validity starts in the future
好像是证书不对?
msh />webclient_pull http://www.rt-thread.com /service/rt-thread.txt
[D/mbedtls.clnt] Set debug level (2)
[D/mbedtls.clnt] mbedtls client struct init success...
[D/mbedtls.clnt] Loading the CA root certificate success...
[D/mbedtls.clnt] mbedtls client context init success...
[D/mbedtls.clnt] Connected www.rt-thread.org:443 success...
[D/mbedtls.clnt] mbedtls_ssl_handshake:6651: => handshake

[D/mbedtls.clnt] mbedtls_ssl_handshake_client_step:3321: client state: 0

[D/mbedtls.clnt] mbedtls_ssl_flush_output:2446: => flush output

[D/mbedtls.clnt] mbedtls_ssl_flush_output:2458: <= flush output

[D/mbedtls.clnt] mbedtls_ssl_handshake_client_step:3321: client state: 1

[D/mbedtls.clnt] mbedtls_ssl_flush_output:2446: => flush output

[D/mbedtls.clnt] mbedtls_ssl_flush_output:2458: <= flush output

[D/mbedtls.clnt] ssl_write_client_hello:0730: => write client hello

[D/mbedtls.clnt] mbedtls_ssl_write_record:2731: => write record

[D/mbedtls.clnt] mbedtls_ssl_flush_output:2446: => flush output

[D/mbedtls.clnt] mbedtls_ssl_flush_output:2464: message length: 410, out_left: 410

[D/mbedtls.clnt] mbedtls_ssl_flush_output:2471: ssl->f_send() returned 410 (-0xfffffe66)

[D/mbedtls.clnt] mbedtls_ssl_flush_output:2490: <= flush output

[D/mbedtls.clnt] mbedtls_ssl_write_record:2889: <= write record

[D/mbedtls.clnt] ssl_write_client_hello:1064: <= write client hello

[D/mbedtls.clnt] mbedtls_ssl_handshake_client_step:3321: client state: 2

[D/mbedtls.clnt] mbedtls_ssl_flush_output:2446: => flush output

[D/mbedtls.clnt] mbedtls_ssl_flush_output:2458: <= flush output

[D/mbedtls.clnt] ssl_parse_server_hello:1457: => parse server hello

[D/mbedtls.clnt] mbedtls_ssl_read_record:3767: => read record

[D/mbedtls.clnt] mbedtls_ssl_fetch_input:2234: => fetch input

[D/mbedtls.clnt] mbedtls_ssl_fetch_input:2391: in_left: 0, nb_want: 5

[D/mbedtls.clnt] mbedtls_ssl_fetch_input:2415: in_left: 0, nb_want: 5

[D/mbedtls.clnt] mbedtls_ssl_fetch_input:2417: ssl->f_recv(_timeout)() returned 5 (-0xfffffffb)

[D/mbedtls.clnt] mbedtls_ssl_fetch_input:2433: <= fetch input

[D/mbedtls.clnt] mbedtls_ssl_fetch_input:2234: => fetch input

[D/mbedtls.clnt] mbedtls_ssl_fetch_input:2391: in_left: 5, nb_want: 70

[D/mbedtls.clnt] mbedtls_ssl_fetch_input:2415: in_left: 5, nb_want: 70

[D/mbedtls.clnt] mbedtls_ssl_fetch_input:2417: ssl->f_recv(_timeout)() returned 65 (-0xffffffbf)

[D/mbedtls.clnt] mbedtls_ssl_fetch_input:2433: <= fetch input

[D/mbedtls.clnt] mbedtls_ssl_read_record:3800: <= read record

[D/mbedtls.clnt] ssl_parse_server_hello:1741: server hello, total extension length: 21

[D/mbedtls.clnt] ssl_parse_server_hello:1930: <= parse server hello

[D/mbedtls.clnt] mbedtls_ssl_handshake_client_step:3321: client state: 3

[D/mbedtls.clnt] mbedtls_ssl_flush_output:2446: => flush output

[D/mbedtls.clnt] mbedtls_ssl_flush_output:2458: <= flush output

[D/mbedtls.clnt] mbedtls_ssl_parse_certificate:4366: => parse certificate

[D/mbedtls.clnt] mbedtls_ssl_read_record:3767: => read record

[D/mbedtls.clnt] mbedtls_ssl_fetch_input:2234: => fetch input

[D/mbedtls.clnt] mbedtls_ssl_fetch_input:2391: in_left: 0, nb_want: 5

[D/mbedtls.clnt] mbedtls_ssl_fetch_input:2415: in_left: 0, nb_want: 5

[D/mbedtls.clnt] mbedtls_ssl_fetch_input:2417: ssl->f_recv(_timeout)() returned 5 (-0xfffffffb)

[D/mbedtls.clnt] mbedtls_ssl_fetch_input:2433: <= fetch input

[D/mbedtls.clnt] mbedtls_ssl_fetch_input:2234: => fetch input

[D/mbedtls.clnt] mbedtls_ssl_fetch_input:2391: in_left: 5, nb_want: 2652

[D/mbedtls.clnt] mbedtls_ssl_fetch_input:2415: in_left: 5, nb_want: 2652

[D/mbedtls.clnt] mbedtls_ssl_fetch_input:2417: ssl->f_recv(_timeout)() returned 2647 (-0xfffff5a9)

[D/mbedtls.clnt] mbedtls_ssl_fetch_input:2433: <= fetch input

[D/mbedtls.clnt] mbedtls_ssl_read_record:3800: <= read record

[D/mbedtls.clnt] mbedtls_ssl_parse_certificate:4633: x509_verify_cert() returned -9984 (-0x2700)

[D/mbedtls.clnt] mbedtls_ssl_send_alert_message:4170: => send alert message

[D/mbedtls.clnt] mbedtls_ssl_write_record:2731: => write record

[D/mbedtls.clnt] mbedtls_ssl_flush_output:2446: => flush output

[D/mbedtls.clnt] mbedtls_ssl_flush_output:2464: message length: 7, out_left: 7

[D/mbedtls.clnt] mbedtls_ssl_flush_output:2471: ssl->f_send() returned 7 (-0xfffffff9)

[D/mbedtls.clnt] mbedtls_ssl_flush_output:2490: <= flush output

[D/mbedtls.clnt] mbedtls_ssl_write_record:2889: <= write record

[D/mbedtls.clnt] mbedtls_ssl_send_alert_message:4183: <= send alert message

[D/mbedtls.clnt] mbedtls_ssl_parse_certificate:4730: <= parse certificate

[D/mbedtls.clnt] mbedtls_ssl_handshake:6661: <= handshake

[E/mbedtls.clnt] verify peer certificate fail....
[E/mbedtls.clnt] verification info: ! The certificate is not correctly signed by the trusted CA
! The certificate validity starts in the future

[E/web] connect failed, https client connect return: -0x1
[E/web.file] get file failed, wrong response: -6 (-0xFFFFFFFA).
[D/mbedtls.clnt] mbedtls_ssl_close_notify:7282: => write close notify

[D/mbedtls.clnt] mbedtls_ssl_close_notify:7298: <= write close notify

上传和下载sample

你好:
1.上传下载的测试sample哪里有呢?
2.是否有显示进度的接口?

谢谢!

https并发通讯时,socket 有 double close 风险

https通讯场景下,使用 webclient_connect 连接成功后, socket fd同时保存在
session->tls_session->server_fd.fd 和 session->socket 中

通讯过程中,如果发生通讯错误, 则会主动调用 closesocket() 关闭通讯socket, 同时只把 session->socket 置为 -1.
此时 session->tls_session->server_fd.fd 中的 fd 号维持不变.
(参考 webclient_read / webclient_write 中的错误处理部分)

通讯过程结束时,如果用户直接使用 webclient_clean 清理现场 , 在https使用场景下,会根据 session->tls_session->server_fd.fd
判定socket是否已经关闭,如其值不为 -1 ,则使用closesocket 主动关闭一次,这里在并发场景下,会有socket double close 风险

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.