我是编程新手(ESP8266)
现在我将来自不同博客的代码片段放在一起,以便从Pushbullet接收(!)推送(消息)。
发送已经很有效,这要归功于:
POST request on arduino with ESP8266 using WifiESP library
Pushbullet的cURL示例是:
set names utf8mb4;
set unique_checks = 0;
set foreign_key_checks = 0;
set sql_log_bin=0;
mysqld select version();
+------------+
| version() |
+------------+
| 5.7.18-log |
+------------+
1 row in set (0.00 sec)
SELECT @@innodb_buffer_pool_size;
+---------------------------+
| @@innodb_buffer_pool_size |
+---------------------------+
| 8388608 |
+---------------------------+
1 row in set (0.00 sec)
Arduino / ESP8266的'翻译':
function memoize(func){
var cache = {};
return function( arg ){
if(arg in cache) {
return cache[arg];
} else {
return cache[arg] = func( arg );
}
}
}
// Overwrite with a function that remember previous results
CalculateForTime = memoize(CalculateForTime);
所以我现在要做的是请求来自Pushbullet的最新消息 cURL中的示例是:
curl --header 'Access-Token: <your_access_token_here>' \
--header 'Content-Type: application/json' \
--data-binary '{"body":"Space Elevator, Mars Hyperloop, Space Model S (Model Space?)","title":"Space Travel Ideas","type":"note"}' \
--request POST \
https://api.pushbullet.com/v2/pushes
我试图让它发挥作用是:
String request = String("POST ") + url +" HTTP/1.1\r\n" +
"Host: " + push_bullet_host + "\r\n" +
"User-Agent: ESP8266/NodeMCU 0.9\r\n" +
"Accept: */*\r\n" +
"Content-Type: application/json\r\n" +
"Content-Length: "+ body.length() +"\r\n" +
"Access-Token: "+ api_token +"\r\n\r\n" +
body;
secure_client.print(req);
但我收到的是以下内容:
curl --header 'Access-Token: <your_access_token_here>' \
--data-urlencode active="true" \
--data-urlencode modified_after="1.4e+09" \
--get \
https://api.pushbullet.com/v2/pushes
我真的很感激任何想法或解决方案。
答案 0 :(得分:0)
active="true"
和modified_after="1496508764"
不是有效标头
你甚至不想在标题中使用它们,因为它们应该是查询参数。
您应该将这些参数附加到网址。
String request = String("GET ") + url +"?active=true&modified_after=1.4e%2B09 HTTP/1.1\r\n" +
"Host: " + push_bullet_host + "\r\n" +
"User-Agent: ESP8266/NodeMCU 0.9\r\n" +
"Accept: */*\r\n" +
"Access-Token: "+ api_token +"\r\n\r\n";
如果您运行curl
或-v
选项,您可以看到--verbose
命令发送和接收的确切内容:
curl --header 'Access-Token: <your_access_token_here>' \
--data-urlencode active="true" \
--data-urlencode modified_after="1.4e+09" \
--get -v\
https://api.pushbullet.com/v2/pushes
有了这个,你会看到:
* ... TLS stuff ...
> GET /v2/pushes?active=true&modified_after=1.4e%2B09 HTTP/1.1
> Host: api.pushbullet.com
> User-Agent: curl/7.42.1
> Accept: */*
> Access-Token: <your_access_token_here>
>
< ... Response headers ...