Socket HTTP POST senden.

lano

Mitglied
Moin.

Wie bekomm ich das am besten hin?
Momentan sieht das so aus. Allerdings müsste ich wohl den HTTP Kram von den POST Daten trennen damit ich die Content Länge richtig angeben kann?

C:
/* juisck */

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#define BUF 4069

int main (int argc, char **argv) {

  int tsocket;

  char *buffer = malloc (BUF);

  struct sockaddr_in address;

  int size;

snprintf(buffer, BUF,
"POST /Jason/UpdateInfoService HTTP/1.1\r\n"
"Host: jws.avm.de:80\r\n"
"Content-Length: 1160\r\n"
"Content-Type: text/xml; charset=\"utf-8\"\r\n\r\n"
"<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:soap-enc= \"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:e=\"http://juis.avm.de/updateinfo\" xmlns:q=\"http://juis.avm.de/request\">\n"
"<soap:Header/>\n"
"<soap:Body>\n"
"<e:BoxFirmwareUpdateCheck>\n"
"<e:RequestHeader>\n"
"<q:Nonce>ixwoteLGzmKa4AefeGbO8w==</q:Nonce>\n"
"<q:UserAgent>Box</q:UserAgent>\n"
"<q:ManualRequest>true</q:ManualRequest></e:RequestHeader>\n"
"<e:BoxInfo>\n"
"<q:Name>FRITZ!Box 7590</q:Name>\n"
"<q:HW>226</q:HW>\n"
"<q:Major>154</q:Major>\n"
"<q:Minor>7</q:Minor>\n"
"<q:Patch>19</q:Patch>\n"
"<q:Buildnumber>77204</q:Buildnumber>\n"
"<q:Buildtype>1001</q:Buildtype>\n"
"<q:Serial>AAAAAAAAAAAA</q:Serial>\n"
"<q:OEM>avm</q:OEM>\n"
"<q:Lang>de</q:Lang>\n"
"<q:Country>049</q:Country>\n"
"<q:Annex>B</q:Annex>\n"
"<q:Flag>crashreport</q:Flag>\n"
"<q:Flag>avm_acs</q:Flag>\n"
"<q:Flag>myfritz_letsencrypt</q:Flag>\n"
"<q:Flag>medium_dsl</q:Flag>\n"
"<q:Flag>mesh_master</q:Flag>\n"
"<q:UpdateConfig>3</q:UpdateConfig>\n"
"<q:Provider>vodafone2_vdsl</q:Provider>\n"
"<q:ProviderName>Vodafone</q:ProviderName></e:BoxInfo></e:BoxFirmwareUpdateCheck></soap:Body></soap:Envelope>");



  if ((tsocket=socket(AF_INET, SOCK_STREAM, 0)) > 0) printf ("Socket wurde angelegt\n");

  address.sin_family = AF_INET;
  address.sin_port = htons (80);
  inet_aton ("212.42.244.118", &address.sin_addr);

    if (connect(tsocket, (struct sockaddr *) &address, sizeof(address)) == 0) {
        printf ("Verbindung mit dem Server (%s) hergestellt\n", inet_ntoa(address.sin_addr));
    }



    send(tsocket, buffer, strlen(buffer), 0);

    size = recv(tsocket, buffer, BUF-1, 0);
      if( size > 0) buffer[size] = '\0';
      printf ("Nachricht erhalten:\n%s\n\n", buffer);



  close (tsocket);
return EXIT_SUCCESS;
}
 
Oben Unten