Re: [Q] How to Forumulate HTTP request using fsockopen() / fputs()

From: Rahul Anand (rahulanand_bis_at_rediffmail.com)
Date: 01/24/04


Date: 23 Jan 2004 22:11:42 -0800


"CountScubula" <me@scantek.hotmail.com> wrote in message news:<hciQb.16439$ED3.14970@newssvr25.news.prodigy.com>...
> "Michael T. Peterson" <mtp1032@comcast.net> wrote in message
> news:550d4e49c99e95f27df0df0d6e84488a@news.teranews.com...
> > I am trying to get the file referenced by the following url:
> >
> >
> http://waterdata.usgs.gov/wa/nwis/uv?dd_cd=01&dd_cd=02&format=rdb&period=1&s
> ite_no=12149000
> >
> > I'm using parse_url to get the host, path, and query. My call to
> > fsockopen() works correctly. Unfortunately, I can find no documentation
> for
> > how to construct a request that will correctly instruct the server (i.e.,
> > waterdata.usgs.gov) to send me the file and all the combinations of
> strings
> > hasn't worked.
> >
> > Can someone point me to some documenation that will explain how to
> construct
> > the query such that file can be obtained? A pointer to code snippets
> would
> > be useful as well, although I would really like to understand the precise
> > semantics.
> >
> > Thanks, in advance,
> >
> > Michael
> >
> >
>
> take a look at this:
>
> http://www-1.gzentools.com/snippetview.php?c=HTTP&v=getresource.php

To read a file from a web-server using HTTP following steps are
needed:

1. Open the socket to domain. [fsockopen]
2. Frame HTTP Request Command. (HEAD or GET) [check HTTP RFC form more
details]
3. Write the command to socket. [fputs/fwrite]
4. Read the socket for returned data. [fgets]
5. Close socket connection.
6. Parse the data to separate Header & Body part.
 
There are other methods also available in PHP:

if you have allow_url_fopen enabled at your server you can use many
other simple functions like:

file_get_contents
file
fopen+fread

etc.

But I think best solution will be using FTP function if you have
access have FTP access.

ftp_connect
ftp_login
ftp_get
ftp_fget

Please check PHP-Manual for more details about these functions.

--
Cheers,
Rahul Anand


Relevant Pages

  • Re: Socket.Disconnect Method
    ... Although the exception list in the MSDN documentation ... Windows XP SP2. ... An error occurred when attempting to access the socket. ... use the SocketException.ErrorCode property to obtain the specific error code. ...
    (microsoft.public.vsnet.general)
  • Re: PHP/pear http put method and text/xml?
    ... As you insisted in a previous posting that the examples serve as documentation, ... When putting it as a binary, the XML ... > And what message appears when you do HTTP PUT with Python or Java? ... > the response when using the PEAR class? ...
    (comp.lang.php)
  • Re: making an http server
    ... > create a socket, bind it to a port number and start listening to the ... transmit it to the browser as a fake HTML response ... > web- this function returns the request back to the browser ... > read from the socket the HTTP request ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Wrapping TCP communications in HTTP
    ... HTTP is a half-duplex protocol. ... The send socket is used to send all requests. ... so the server can return any data it has. ...
    (microsoft.public.win32.programmer.networks)
  • Re: RPGIV Socket Help
    ... socket that uses the POST as opposed to GET? ... Look up the HTTP specs and see how a post should look. ... I want to connect to one of our vendors web services, ... and download a formatted text file to the IFS. ...
    (comp.sys.ibm.as400.misc)

Loading