2017-05-09 65 views
3

下面是关于Arduino的运行代码,使用Webduino库:Webduino接收来自卷曲post数据,但不会从节点

void handleConfigRequest(WebServer &server, WebServer::ConnectionType type, char *, bool) { 

// POST request to receive new config 
if (type == WebServer::POST) { 

    bool repeat; 
    char name[16], value[50]; 

    do { 
     // Returns false when no more params to read from the input 
     repeat = server.readPOSTparam(name, 16, value, 50); 

     if (strcmp(name, "dName") == 0) { 
     strcpy(deviceName, value); 
     Serial.println(value); 
     } 
    } while (repeat); 
} 

可正常工作(并打印“测试”通过串行)在执行时以下在命令行上的卷曲:

卷曲http://10.0.1.141/config -D “DNAME =测试”

我还测试了单重H TML形式,提交时也可以工作,并打印“测试”通过串行:

<form action="http://10.0.1.141/config"> 
    <input type="text" name="dName" value="test"> 
    <input type="submit" value="Send"> 
</form> 

但是,下面的Node.js的使用request代码不起作用:

var options = { 
    url: "http://10.0.1.141/config", 
    headers: { 
     "Content-Type": "application/x-www-form-urlencoded", 
     "Accept": "*/*", 
     "User-Agent": "TestingScript" 
    }, 
    form: {dName: "Test"} 
    } 

    request.post(options, function(error, response, body) { 
    console.log(error, response, body) 
    }) 

使用节点代码, Arduino确认HTTP POST请求(在这种情况下,通过闪烁LED),但不会将“测试”打印为串行。

我已经指出这两个卷曲,并在requestb.in页我节点的代码,你可以看到,请求自己似乎是相同的(一个底部是卷曲,上面是我的):

Requestbin

有什么建议吗?

+0

为什么节点版本使用“https”开头的“CF-游客”头?网络灯是否闪烁,但Webduino忽略HTTPS请求? –

+0

我没有看到在节点代码任何可能使其HTTPS - 我认为这更多的是与Requestb.in如何使用SSL在内部与CloudFlare的 – Alfo

+0

尝试强制用户代理,以“卷曲/ 7.51.0”? –

回答

0

最后,我取代了节点request代码下面的jQuery:

$.ajax({ 
    type: "POST", 
    url: "http://10.0.1.141/config", 
    data: {dName: "Test"} 
}, function(data({ 
    console.log(data) 
} 

后就正常了。奇。

+0

滑稽 - 使用IBM Bluemix时发生同样的问题相同... – Fattie