Ethernet W5100

I am using Arduino Uno and Ethernet W5100.With these device I want to post sensor data to server with post command .I am able to get data but I am not able to post data on the given server .I am just beginner and I dont have any ideas about coding. Please help me and tell me how could I send data to server with post command.

#include <Ethernet.h>
#include<SPI.h>

EthernetClient client;
uint8_t mac[6] = {0x00,0x01,0x02,0x03,0x04,0x05};

void setup() {
  Serial.begin(9600);

  char server[] = "www.circuitxcode.com";

  String data = "sensor1=";
  data += analogRead(A0);
  //data += "sensor2=";
  //data += analogRead(A1);
  if(Ethernet.begin(mac) == 0){
    Serial.println("Failed to configure Ethernet using DHCP");
    while(1);
  }

  if (client.connect(server,80)){
      Serial.println("Connected to server");
      client.println("POST /sensor.php HTTP/1.1");
      client.println("Host: circuitxcode.com");
      client.println("Content-Type: application/x-www-form-urlencoded");
      client.print("Content-Length: ");
      client.println(data.length());
      client.println();
      client.println(data);
      client.println();
  }else{
      Serial.println("Connection to server failed");
  }
}

void loop() {  
  while(client.connected()){
    if(client.available()){
      char c = client.read();
      Serial.print(c);  
    }
  }
}

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