Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 从GET请求跳过HTTP头_Node.js_Arduino_Esp8266 - Fatal编程技术网

Node.js 从GET请求跳过HTTP头

Node.js 从GET请求跳过HTTP头,node.js,arduino,esp8266,Node.js,Arduino,Esp8266,我的项目需要帮助。 这是我的密码: void ConexaoServer(){ uint8_t buffer[1024] = {0}; if (wifi.createTCP(HOST_NAME, HOST_PORT)) { Serial.print("Conexao com o Host OK!\r\n"); } else { Serial.print("Conexao com o Host com ERRO!\r\n"); }

我的项目需要帮助。 这是我的密码:

void ConexaoServer(){
    uint8_t buffer[1024] = {0};

    if (wifi.createTCP(HOST_NAME, HOST_PORT)) {
        Serial.print("Conexao com o Host OK!\r\n");
    } else {
        Serial.print("Conexao com o Host com ERRO!\r\n");
    }

    char *ComandoGET = "GET /teste HTTP/1.1\r\nHost: SmartHome\r\nConnection: close\r\n\r\n";
    wifi.send((const uint8_t*)ComandoGET, strlen(ComandoGET));

    uint32_t len = wifi.recv(buffer, sizeof(buffer), 10000);
    if (len > 0) {
        Serial.print("Received:[");
        for(uint32_t i = 0; i < len; i++) {
            Serial.print((char)buffer[i]);
        }
        Serial.print("]\r\n\r\n");
    }
}

但我只想接收
已接收:[Luiz]
。我如何做到这一点?

您需要找到双换行符(
\r\n\r\n
),然后使用字符

char有效载荷[1024]=“”;
char*pl=strstrstr((char*)缓冲区,“\r\n\r\n”);
如果(pl!=NULL)
{
strcpy(有效载荷,pl+4);
Serial.println(有效载荷);
}

您需要找到双换行符(
\r\n\r\n
),然后使用字符

char有效载荷[1024]=“”;
char*pl=strstrstr((char*)缓冲区,“\r\n\r\n”);
如果(pl!=NULL)
{
strcpy(有效载荷,pl+4);
Serial.println(有效载荷);
}

为什么不从node(js land)本身执行HTTP请求?这样您就不必手动解析HTTP…@mscdex我在Node.js中是如何做到的?这是我在app.js var express=require('express')中的代码;var-app=express();get('/teste',function(req,res){res.send('helloworld!');});var server=app.listen(3000,“localhost”,函数(){var host=server.address().address;var port=server.address().port;console.log('Exemplo na URL http://%s:%s',host,port);});为什么不从节点(jsland)本身执行HTTP请求呢?这样您就不必手动解析HTTP…@mscdex我在Node.js中是如何做到的?这是我在app.js var express=require('express')中的代码;var-app=express();get('/teste',function(req,res){res.send('helloworld!');});var server=app.listen(3000,“localhost”,函数(){var host=server.address().address;var port=server.address().port;console.log('Exemplo na URL http://%s:%s',host,port);});