首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Webduino从卷发中接收邮件,但没有从Node接收

Webduino从卷发中接收邮件,但没有从Node接收
EN

Stack Overflow用户
提问于 2017-05-09 15:01:30
回答 1查看 199关注 0票数 3

下面是使用韦迪诺库在Arduino上运行的代码:

代码语言:javascript
复制
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);
}

当在命令行上从curl执行以下操作时,这将按预期工作(并在串行上打印"Test“):

卷曲http://10.0.1.141/config -d "dName=Test“

我还测试了一个简单的HTML表单,它在提交时还可以在串行上打印"Test“:

代码语言:javascript
复制
<form action="http://10.0.1.141/config">
  <input type="text" name="dName" value="test">
  <input type="submit" value="Send">
</form>

但是,以下使用Node.js代码的请求不起作用:

代码语言:javascript
复制
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)
  })

使用Node代码,Arduino确认HTTP请求(在本例中,通过闪烁LED),但不将"Test“打印为串行。

我将curl和Node代码都指向了一个requestb.in页面,您可以看到请求本身似乎是相同的(下面的是curl,顶部是我的):

有什么建议吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-11 14:07:44

最后,我将Node request代码替换为以下jQuery:

代码语言:javascript
复制
$.ajax({
  type: "POST",
  url: "http://10.0.1.141/config",
  data: {dName: "Test"}
}, function(data( {
  console.log(data)
}

效果很好。很奇怪。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43873339

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档