根据请求将变量插入url esp8266

时间:2019-03-20 10:12:09

标签: arduino telegram telegram-bot esp8266 arduino-esp8266

  

我想编写一个程序,以编解码器向BotTelegram发送消息   我使用WifiClientSecure进行HTTPS请求,我知道有一个   ESP8266的电报bot库,但出于某种原因,我不想使用它。   这使其成为问题,即url和变量之间的组合   令牌,总是有问题

String token ="xxxx:xxxxxx_xxxxxxxxxxx";
String chat_id ="xxxxxx";    
String url = "/bot"+token+"/sendMessage?chat_id="+chat_id+"&text=node";
          Serial.print("requesting URL: ");
          Serial.println(url);


        String request = String("GET ") + url + " HTTP/1.0\r\n" +
                         "Host: " + host + "\r\n" +
                         "Accept: *" + "/" + "*\r\n" +
                          "User-Agent: BuilderFailureDetectorESP8266\r\n" +
                          "Connection: close\r\n\r\n" ;
          Serial.println(request);               
          client.print(request);

并在请求按以下方式发送之前输出

GET /botxxxx:xxxxxx_xxxxxxxxxxx
  

仅在令牌之前显示,这就是导致请求失败的原因。但   如果我直接输入而不输入变量,则运行nomal不会   问题,就像下面的那个

String url = "/botxxxx:xxxxxx_xxxxxxxxxxx/sendMessage?chat_id=xxxxxx&text=node";
          Serial.print("requesting URL: ");
          Serial.println(url);


        String request = String("GET ") + url + " HTTP/1.0\r\n" +
                         "Host: " + host + "\r\n" +
                         "Accept: *" + "/" + "*\r\n" +
                          "User-Agent: BuilderFailureDetectorESP8266\r\n" +
                          "Connection: close\r\n\r\n" ;
          Serial.println(request);               
          client.print(request);

任何人都可以帮助我,我尝试添加String(token),但是效果不佳

0 个答案:

没有答案