How to get response server from POST request? (W5100)

How to get response server from POST request?

String responce;
  if (client2.connect(serverName, 80)) {
    if (DEBUG) Serial.println("connected, sending \""+data+"\"");
    client2.println("POST /a.php HTTP/1.1");
    client2.println("Host: " + serverName); 
    client2.println("Connection: keep-alive");
    client2.println("Cache-Control : no-cache");
    client2.println("Pragma: no-cache");
    client2.println("Expires: -1");
    client2.println("Content-Type: application/x-www-form-urlencoded");
    client2.print("Content-Length: ");
    client2.println(data.length());
    client2.println();
    client2.print(data);
 
--- Need a response from the server ---

    client2.stop();
    client2.flush();
    if (DEBUG) Serial.println("responce = " + responce);
  }
  else {
    if (DEBUG)    Serial.println("connection failed");
  }

Where did you get the code? Pull it out of thin air?

Use WebClient example sketch as a starting point. It is written for GET.
You need to change it so that it continues reading after you get the empty line.

Use the second example here. It starts about halfway down the page.
http://playground.arduino.cc/Code/WebClient

ieee488:
Where did you get the code?

what code?

   client2.println("POST /a.php HTTP/1.1");
   client2.print("Host: "); 
   client2.println(serverName); 
   client2.println("Connection: keep-alive");
   client2.println("Cache-Control : no-cache");
   client2.println("Pragma: no-cache");
   client2.println("Expires: -1");
   client2.println("Content-Type: application/x-www-form-urlencoded");
   client2.print("Content-Length: ");
   client2.println(data.length());
   client2.println();
   client2.print(data);

  while (client2.available())
   {
     char c = client2.read();
     responce += c;
   }

I think server not catch answer.

Use the second example here. It starts about halfway down the page.

Thank, i'll try it.

You must evaluate the connection status. The server will close the connection when it is finished sending packets.

This is the "Perfect World" version. The "Real World" version is in the playground link. It has a timeout feature that prevents the "while(client2.connected())" loop from becoming an infinite loop in the event of a connection fail.

// while the server is connected
while(client2.connected()) {
   // get another packet if available
   while (client2.available())
   {
     char c = client2.read();
     responce += c;
   }
}
// close the connection on client end
client2.stop();

SurferTim, thank, it work fine.

Responce without headers i get so:

responce.substring(responce.indexOf("\r\n\r\n") + 4);

NickName:
what code?

SERIOUSLY ? ? ?

You don't know what code is ? ? ?

Then what have you been writing? Spaghetti ? ? ?

P. S. response is spelled with an s

Code in first post.