Server response correctly but PHP file doesn't receive any data

I'm trying to build an attendance system based on RFID and NODEMCU, the NODEMCU send POST request to PHP file but PHP file doesn't receive any data, so I decided to intercept network traffic and I saw that server response correctly. This is Server response and this is POST request from client this is php code

<?php

echo $data = isset($_POST['uid']) ? $_POST['uid'] : 'no data';

?>

this is arduino code

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <MFRC522.h>
#include <SPI.h>

const char* ssid = "Bam";
const char* password = "123456789";
const char* target = "http://192.168.1.109/RFID/getuid.php";

MFRC522 reader(D4, D3);
void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  SPI.begin();
  reader.PCD_Init();
  WiFi.begin(ssid, password);
  while(WiFi.status() != WL_CONNECTED){
    delay(1000);
    Serial.println("Connecting to " + String(ssid) + "...");
  }
  Serial.println("Connected to "+String(ssid)+"!");

}

void loop() {
  // put your main code here, to run repeatedly:
  if(reader.PICC_IsNewCardPresent() && reader.PICC_ReadCardSerial()){
    String uid = "";
    for(byte i=0; i<reader.uid.size;i++){
      uid+=String(reader.uid.uidByte[i] < 0x10 ? "0" : "");
      uid+=String(reader.uid.uidByte[i], HEX);
    }
    Serial.println("Card UID: "+uid);
    sendUid(uid);
    delay(1000);
  }

}
void sendUid(String uid){
  if(WiFi.status() == WL_CONNECTED){
    WiFiClient client;
    HTTPClient http;
    http.begin(client, target);
    http.addHeader("Content-Type", "application/x-www-form-urlencoded");
    String data = "uid="+uid;
    int httpResCode = http.POST(data);
    if(httpResCode == HTTP_CODE_OK){
      String res = http.getString();
      Serial.println("Server response: "+res);
    }else{
      Serial.println("HTTP error code: "+ String(httpResCode));
    }
    http.end();
  }else{
    Serial.println("WiFi not connected");
  }
}

The WireShark output says something different. The server answered the POST request correctly as the PHP code tells it. It may not be what you expected it to do but as you didn't tell us what you expected we can only say: everything runs correctly.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.