Re Milan Roubal:: c-cko socket(), HTTP, POST poziadavok

www www na inmail.sk
Pondělí Únor 4 20:01:28 CET 2002


Diki za postreh.Ale aj tak mi to vypise tento vypis:
===========================================
HTTP/1.1 200 OK
Date: Thu, 31 Jan 2002 13:05:00 GMT
Server: Apache/1.3.12 (Unix)  (Red Hat/Linux) mod_czech/3.1.0 PHP/3.0.16
X-Powered-By: PHP/3.0.16
Vary: User-Agent, Accept-Charset
Transfer-Encoding: chunked
Content-Type: text/html; charset=iso-8859-2

15
<html>
Si
</html>
0
===========================================

Takze co teraz?Preco mi tam nevypise meno?
Dik

> zamen radek
> >   sprintf(buf,"POST http://localhost/index.php3 HTTP/1.1\r\n");
> za
> >   sprintf(buf,"POST http://localhost/odpoved.php3 HTTP/1.1\r\n");
>
>     Zdravi
>     Milan Roubal
>     roubm9am na barbora.ms.mff.cuni.cz


=============odpoved.php3===============================
<html>

Si   <?echo $meno?>

</html>
=====================================================


================program.c==============================
#include <stdio.h>
#include <stdlib.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdarg.h>


#define PORT  80

main()
{
  int sock;
  char odoslat[100];
  char server[100];
  char prijem[2600];
  char buf[1024];

  struct sockaddr_in sin;
  struct hostent *hp;

  strcpy(server, "localhost");
  hp = gethostbyname(server);
  if (hp==NULL) {
    printf("Unknown host: %s\n",server);
    exit(0);
  }

  bzero((char*) &sin, sizeof(sin));
  bcopy(hp->h_addr, (char *) &sin.sin_addr, hp->h_length);
  sin.sin_family = hp->h_addrtype;
  sin.sin_port = htons(PORT);
  sock = socket(AF_INET, SOCK_STREAM, 0);
  connect(sock,(struct sockaddr *) &sin, sizeof(sin));

  strcpy(odoslat, "meno=Martin");

  sprintf(buf,"POST http://localhost/odpoved.php3 HTTP/1.1\r\n");
  send(sock, buf, strlen(buf),0);
  sprintf(buf,"User-Agent: Mozilla/4.0 (compatible; MSIE 4.01; Windows
NT)\r\n");
  send(sock, buf, strlen(buf),0);
  sprintf(buf,"Host: %s\r\n", server);
  send(sock, buf, strlen(buf),0);
  sprintf(buf,"Accept-Charset: iso-8859-2, windows-1250; q=0.8, us-ascii;
q=0.2\r\n");
  send(sock, buf, strlen(buf),0);
  sprintf(buf,"Content-type: text/html\r\n");
  send(sock, buf, strlen(buf),0);
  sprintf(buf,"Content-length: %d\r\n", strlen(odoslat));
  send(sock, buf, strlen(buf),0);
  sprintf(buf,"\r\n");
  send(sock, buf, strlen(buf),0);
  sprintf(buf,"%s\r\n", odoslat);
  send(sock, buf, strlen(buf),0);

  read(sock,prijem, 1600, 0);

  printf("%s\n", prijem);

}
===========================================================




Další informace o konferenci Linux