posting on ethernet shield

Hi,

I've just got my ethernet shield and all is working ok. I'm trying to send an xml file to my work sms gateway. But I don't know how to code it.

I have managed to store the xml file into flash using the flash library and a big_string and can output that to the serial console no problem. What I need to do is a http post to hxxp://yourdomain.com/SMSSite/XMLInterface/Postxml.aspx?XMLDATA= then the xml data.

Now do I do this:-

client.println("post hxxp://yourdomain.com/SMSSite/XMLInterface/Postxml.aspx?XMLDATA= HTTP/1.0");

client.println(big_string);

or

client.println("post");
client.println(sms_url); //declare this above somewhere
client.println("HTTP/1.0");
client.prinln(big_string);

any help would be good!!! :wink:

Cheers
Bucky.

Luckily there are two ways you can pass data to a web server...

Include it as a QueryString (like you are doing)
For that you will have to probably either Base64 encode it, unless it is just plain text.

try this:

client.print("GET hxxp://yourdomain.com/SMSSite/XMLInterface/Postxml.aspx?XMLDATA=");
client.print(big_string);
// finish off the line.
client.println(" HTTP/1.0");
// tell the server you are done with the header. (a /r/n signals the content is to follow, but since you don't have content to post (it is in the query string) just end the request.
client.println();

**Or, Post it. **Change it up to do this:

client.println("POST hxxp://yourdomain.com/SMSSite/XMLInterface/Postxml.aspx HTTP/1.0");
// add a header indicating you have content-data to send.  If you set this too low, the server won't see it.  If it is too high, the server may wait, or report an error.
client.print("content-length: ");
client.println(strlen(big_string));
// tell the server you are done with the header.
client.println();
// send the posted data.
client.print(big_string);

On my server for a binary-communication project using the second POST method (immediately above), I have a IHttpHandler that uses BinaryRead on the InputStream. Using BinaryStream.Length, I can tell how large the data is, and then BinaryRead it. I assume StreamReader and StreamReader.ReadAll() would do the same for you if it is ASCII/UTF.

Thanks will give it ago and see if it works :-/

Doesnt work! tried both methods. All i get from the server is the webpage contents no messages.

I am going to assume for the moment that you mean "not what you expected, instead of "web page instead of a message..."

:stuck_out_tongue:

When the response comes back, part of the HTTP protocol is to send headers, then the message. The headers outline what the content is, who the server is, what the request was, etc. and are separated from the "page" or message in your case by things that normally tell the browser what to do. The separation of the headers is a blank line (/r/n)

Skip past the header, unless you want to know one of the items and you will see your message. You can check content-length, for example - it will be the number of bytes in your message.

Here is the code I have to skip past the header:

bool readPastHeader(Client *pClient)
{
  bool bIsBlank = true;
  while(true)
  {
    if (pClient->available()) 
    {
      char c = pClient->read();
      if(c=='\r' && bIsBlank)
      {
        // throw away the /n
        c = pClient->read();
        return true;
      }
      if(c=='\n')
        bIsBlank = true;
      else if(c!='\r')
        bIsBlank = false;
      }
   }
}

Note: This also skips past the response codes (401, auth required, 403 file not found, 500 server errror) - if you need to check those, you will have to parse the headers out.

I have a system posting data to my webserver every 15 seconds using this exact code, and each days about 300kb of logs for each transfer to show for it.