Re: Reading the content.
| From: | Gustavo Carreno | Date: | Wed, 11 Jul 2001 15:45:08 +0000 |
| Subject: | Re: Reading the content. | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-57405@lists.php.net to get a copy of this message | ||
> Are you sure? I tested posting to a script which simply did a
> print_r($GLOBAL), and didn't see the posted data listed.
Yeaps, if the content-type is known the $HTTP_RAW_POST_DATA is empty
and does not show on the $GLOBALS.
Try this C program in Linux and you'll get surprised:
---------- httppost.c --------------------------------------------------
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <errno.h>
int
main(void)
{
int sockfd, connfd, error;
socklen_t len;
struct sockaddr_in sa, csa;
char line[1025];
if ((sockfd=socket(AF_INET, SOCK_STREAM, 0))<0)
{
printf("error in socket()\n");
exit(1);
}
bzero(&sa, sizeof(sa));
sa.sin_family=AF_INET;
if (inet_aton("194.79.65.203",&sa.sin_addr)<0)
{
printf("error on inet_aton\n");
exit(1);
}
sa.sin_port=htons(80);
if (connect(sockfd, &sa, sizeof(sa))<0)
{
printf("error on connect\n");
exit(1);
}
sprintf(line,"POST /dl_bulk.php HTTP/1.0\r\n");
printf("Sending: %s",line);
write(sockfd, &line, strlen(line));
sprintf(line,"Host: test.datascan.c3im.pt\r\n");
printf("Sending: %s",line);
write(sockfd, &line, strlen(line));
sprintf(line,"Content-type: text/xml\r\n");
printf("Sending: %s",line);
write(sockfd, &line, strlen(line));
sprintf(line,"Content-length: 38\r\n\r\n");
printf("Sending: %s",line);
write(sockfd, &line, strlen(line));
sprintf(line,"<?xml
version=\"1.0\"?>\r\n<bla>\r\n</bla>\r\n");
printf("Sending: %s",line);
write(sockfd, &line, strlen(line));
printf("Reading:\n");
while(read(sockfd, &line, 2048))
{
line[strlen(line)+1]=0;
printf("%s",line);
}
close(sockfd);
}
---------- httppost.c --------------------------------------------------
and this is the dl_bulk.php contents:
---------- dl_bulk.php ------------------------------------------------
<?
header("Content-type: text/xml");
print($HTTP_RAW_POST_DATA);
?>
---------- dl_bulk.php ------------------------------------------------