【发布时间】:2018-01-20 03:55:11
【问题描述】:
我有一个运行 Node.JS 服务器的 Intel Edison,它将我发布到它的所有内容打印到控制台中。我可以使用 Postman 成功发布到它,并在控制台中查看发送的原始数据。
现在我正在使用处理向它发布,这将在 Node.JS 服务器上触发不同的事件。
我的问题是我似乎无法成功地将原始正文发布到服务器,我已经尝试了几个小时。
import processing.net.*;
String url = "192.168.0.107:3000";
Client myClient;
void setup(){
myClient = new Client(this, "192.168.0.107", 3000);
myClient.write("POST / HTTP/1.1\n");
myClient.write("Cache-Control: no-cache\n");
myClient.write("Content-Type: text/plain\n");
//Attempting to write the raw post body
myClient.write("test");
//2 newlines tells the server that we're done sending
myClient.write("\n\n");
}
控制台显示服务器收到了 POST 和正确的标头,但其中没有显示任何数据。
如何指定“测试”是原始 POST 数据?
来自 Postman 的 HTTP 代码:
POST HTTP/1.1
Host: 192.168.0.107:3000
Content-Type: text/plain
Cache-Control: no-cache
Postman-Token: 6cab79ad-b43b-b4d3-963f-fad11523ec0b
test
来自 Postman 的 POST 的服务器输出:
{ host: '192.168.0.107:3000',
connection: 'keep-alive',
'content-length': '4',
'cache-control': 'no-cache',
origin: 'chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop',
'content-type': 'text/plain',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36',
'postman-token': 'd17676a6-98f4-917c-955c-7d8ef01bb024',
accept: '*/*',
'accept-encoding': 'gzip, deflate',
'accept-language': 'en-US,en;q=0.8' }
test
我的 POST 来自 Processing 的服务器输出:
{ host: '192.168.0.107:3000',
'cache-control': 'no-cache',
'content-type': 'text/plain' }
{}
【问题讨论】:
标签: http http-headers processing postman intel-edison