2017-05-09 22 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