arduino esp8266 请求服务器未得到响应(ESP8266HTTPClient)

学习太极创客esp8266 服务器的基本操作,遇到了因版本不同导致编译无法通过;

此问题为我们在arduino下载的esp8266的版本为3.0.2版本,和官方给出来的历程所用的版本不同所导致的,我们需要添加两行代码

1、在begin()函数前面添加此代码

 2、需要将报错的函数加上一个参数,这是高版本esp8266的不同的地方

同时,编译成功后,端口无法获取到服务器响应的数据,HTTP发出的请求未得到响应,返回的结果为-1

WiFi Connected!URL: http://www.example.com
Send GET request to URL: http://www.example.com
Server Respose Code:
-1

未得到响应返回一个-1,那么我们在发送HTTP请求的同时设置让我们的程序未得到程序就一直在执行HTTP请求,得到响应则退出循环。

 //重点3 通过GET函数启动连接并发送HTTP请求
 
  int httpCode = httpClient.GET();
  while(httpCode == -1)
  {
    httpCode = httpClient.GET();
  }
  Serial.print("Send GET request to URL: ");
  Serial.println(URL);

最后:

⸮⸮|⸮`⸮l,⸮4b>⸮⸮⸮x⸮Z⸮⸮....
WiFi Connected!URL: http://www.example.com
Send GET request to URL: http://www.example.com
Server Response Payload: 
<!doctype html>
<html>
<head>
    <title>Example Domain</title>

    <meta charset="utf-8" />
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <style type="text/css">
    body {
        background-color: #f0f0f2;
        margin: 0;
        padding: 0;
        font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
        
    }
    div {
        width: 600px;
        margin: 5em auto;
        padding: 2em;
        background-color: #fdfdff;
        border-radius: 0.5em;
        box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);
    }
    a:link, a:visited {
        color: #38488f;
        text-decoration: none;
    }
    @media (max-width: 700px) {
        div {
            margin: 0 auto;
            width: auto;
        }
    }
    </style>    
</head>

<body>
<div>
    <h1>Example Domain</h1>
    <p>This domain is for use in illustrative examples in documents. You may use this
    domain in literature without prior coordination or asking for permission.</p>
    <p><a href="https://www.iana.org/domains/example">More information...</a></p>
</div>
</body>
</html>


  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值