httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lee Fellows <lfell...@4lane.com>
Subject Re: socket programming
Date Tue, 16 Apr 2002 20:54:16 GMT
Hi,

  Just to add to what Svein Olav Bjerkeset wrote:  there are a number
of HTTP headers defined in the HTTP protocol.  One of these headers,
the HTTP_HOST header, is what the server uses to identify which
Virtual Host to connect to when using Named Virtual Hosts.  You would
need to define and send this header to visit a domain other than the
default domain for a site that is using Named Virtual Hosts. 
www.w3.org/Protocols/ could be a helpful place to start.

HTH

On Tue, 2002-04-16 at 16:26, Svein Olav Bjerkeset wrote:
> Hi,
> 
> Try to substitute
>    sprintf (buffer, "GET %s\n", http_page);
> 
> with
>     sprintf (buffer, "GET %s HTTP/1.0\n\n", http_page);
> 
> Remember: The HTTP request should be terminated by TWO newlines.
> 
> Svein Olav Bjerkeset
> 
> ----- Original Message -----
> From: "Carlos Pereira" <carlos@pehoe.civil.ist.utl.pt>
> To: <users@httpd.apache.org>
> Sent: Tuesday, April 16, 2002 9:39 PM
> Subject: socket programming
> 
> 
> > Hi there,
> >
> > I prepared this 49-line C program (from books and web resources,
> > I am just a socket programming newbie), which is
> > supposed to read a http web page and print it to the terminal:
> >
> > for example to read the root page,
> > say index.html, of the site www.my_site.org:
> >
> > a.out www.my_site.org /
> >
> > <html>
> > <head>
> > <title>
> > Welcome...
> > </title>
> > etc..
> >
> > This works fine with all the websites here in this
> > universitary campus, but when I try other sites
> > it just hangs on, just trying to read and then
> > the connection is closed. Is this a problem with
> > my socket programming code or is it due to something
> > else? security issues or something? DNS? closed services?
> > I am testing on sites that my browsers read without
> > problems.
> >
> > Other question is, how can I handle virtual hosts?
> > (as defined by apache in httpd.conf)
> > because as it is, the code always shows the pages of
> > the first virtual host. Which modifications shall I
> > introduce to my code? I would like to use this to allow
> > users of my GPL code to import XML files from remote
> > locations (using entities), not just from the local
> > computer (is working fine apart from those problems)
> >
> > And if this is the wrong place to ask this
> > just point me to the right place and accept
> > my apologies. Thanks!
> >
> > Carlos
> >
> >
> > --------socket.c------tested on Linux Red Hat 5.2-------
> > #include <stdlib.h>
> > #include <stdio.h>
> > #include <netinet/in.h>
> > #include <netdb.h>
> > #include <sys/socket.h>
> > #include <unistd.h>
> > #include <string.h>
> >
> > void get_page (int socket_fd, char *http_page)
> > {
> > char buffer[1024];
> > ssize_t size;
> >
> > sprintf (buffer, "GET %s\n", http_page);
> > write (socket_fd, buffer, strlen (buffer));
> > while (1)
> >   {
> >   if ((size = read (socket_fd, buffer, 1024)) == 0) return;
> >   fwrite (buffer, sizeof (char), size, stdout);
> >   }
> > }
> >
> > main (int argc, char **argv)
> > {
> > int socket_fd;
> > struct sockaddr_in name;
> > struct hostent* host;
> > struct servent *service;
> >
> > if ((host = gethostbyname (argv[1])) == NULL)
> >   { printf ("error_host\n"); return 1; }
> >
> > if ((service = getservbyname("http", "tcp")) == NULL)
> >   { printf ("error_service\n"); return 1; }
> >
> > name.sin_family = AF_INET;
> > name.sin_addr = *((struct in_addr *) host->h_addr);
> > name.sin_port = service->s_port;
> >
> > if ((socket_fd = socket (PF_INET, SOCK_STREAM, 0)) < 0)
> >   { printf ("error_socket\n"); return 1; }
> >
> > if (connect (socket_fd, &name, sizeof (struct sockaddr_in)) < 0)
> >   { printf ("error_connect\n"); return 1; }
> >
> > get_page (socket_fd, argv[2]);
> >
> > return 0;
> > }
> > ---------------sockect.c------------------------------
> >
> > ---------------------------------------------------------------------
> > The official User-To-User support forum of the Apache HTTP Server Project.
> > See <URL:http://httpd.apache.org/userslist.html> for more info.
> > To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> > For additional commands, e-mail: users-help@httpd.apache.org
> >
> 
> 
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
> 
> 



---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Mime
View raw message