phummon 0 Newbie Poster

Hi everyone,

I'm a moderately experienced C++ programmer who's trying to do a little socket work. Don't ask why, but I'm to write a program which, when activated, sends an HTTP POST request to a remote end server. The socket part of the work is done and successfully tested; all I have to do is get the HTTP header exactly right. Unfortunately, the resources I've consulted online aren't that helpful and I can't tell where I'm screwing up the header. Can someone quickly spot the error or recommend a solid resource which will really detail what I want to do?

Here's the HTTP request I'm sending to the remote server:

POST /login.jsp HTTP/1.1
Content-Length: 170
Content-Type: text/html; charset=ISO-8859-4

<Payload>...stuff here...</Payload>


For those of you who are curious, here's the code (briefer than it looks):


void BuildPayload(string* PtrPayloadBuffer, string Stuff)
  string Part1="<Payload>";
  string Part2="</Payload>";


void BuildHeader(string* PtrHeaderBuffer, string* PtrPayloadBuffer, sockaddr_in RemoteServer)
  string Part1="POST /login.jsp HTTP/1.1\nHost: ";
  string Part2="\nContent-Length: ";
  string Part3="\nContent-Type: text/html; charset=ISO-8859-4\r\n\r\n";
  char * MsgSize=(char*) malloc (sizeof(char) * 5);  memset(MsgSize,0,5);
  int DontCare;
  DontCare=sprintf(MsgSize, "%d", PtrPayloadBuffer->size());

  (*PtrHeaderBuffer).append("");   // don't know how to encode IP Addr as string

int main(int argc, char * argv[])
  // Build socket to remote server

  BuildPayload(PtrPayloadBuffer, AppName, L4Proto, L4Port);
  BuildHeader(PtrHeaderBuffer, PtrPayloadBuffer, RemoteServer);

  // Write string HeaderBuffer to socket, then close

  return 1;