How to retrieve a webpage via C....
  • Paladin of the Pegasos
    Paladin of the Pegasos
    TheMagicM
    Posts: 1220 from 2003/6/17
    Anyone have any sample code? I want to be able to retrieve a webpage for a project I'm working on.

    Sample code would be great.

    -Alex
  • »10.03.04 - 15:07
    Profile Visit Website
  • Order of the Butterfly
    Order of the Butterfly
    Chain-Q
    Posts: 347 from 2003/10/12
    From: 1 AU, EU, DE/HU
    You need to use standard networking API. You can found more information about network programming for example here.

    Amiga/MOS specific implementation of this API is in bsdsocket.library, provided by the TCP/IP stack. You can found more information about this specific implementation in the MiamiDX SDK, or here.

    To retrieve a webpage, you need to use HTTP protocol. You can find more information about HTTP/1.1 protocol here.
    You can also learn a lot from opensource HTTP clients, for eg. WGet. I also wrote a small HTTP retriever, which can parse the URL, and fetch files from a HTTP server. It's in PowerD and not C, but i can send it to you if you want it, just PM me.
    [.PegasosII/G4.:.Efika.:.Amiga2000/060.]
    [.Free Pascal Compiler MorphOS Port.]
    [.Hosting AmigaSpirit.hu.]
  • »10.03.04 - 15:21
    Profile Visit Website
  • Paladin of the Pegasos
    Paladin of the Pegasos
    TheMagicM
    Posts: 1220 from 2003/6/17
    thanks for the info...thats what I was looking for.
  • »10.03.04 - 15:29
    Profile Visit Website
  • Cocoon
    Cocoon
    porneL
    Posts: 49 from 2003/7/16
    I have my old C code and new pretty slick C++ code if you're interested.

    HTTP RFC is lenghty and hard to read if you're not familiar with BNF notation, but but protocol itself is quite simple.

    Generally you need to create a socket, resolve domain, connect socket to specified ip/port and send:

    GET /path/on/server HTTP/1.1\r\n
    Host: domain.com\r\n
    \r\n

    If all went fine In reply you'll get:
    HTTP/1.1 200 OK\r\n
    Some-Headers: here\r\n
    \r\n
    requested page


    Be careful with recv()/send() commands - they don't have to read/send all data you requested. You need either specify flag (which I dont remember now :)) or execute them in loop.
    this text is here to confuse you
  • »10.03.04 - 16:49
    Profile
  • Paladin of the Pegasos
    Paladin of the Pegasos
    TheMagicM
    Posts: 1220 from 2003/6/17
    yes I wouldnt mind seeing your code.. beats a whole lot of readin'...

    email it to:
    bartonekdragracing at yahoo dot com
  • »10.03.04 - 17:58
    Profile Visit Website
  • Just looking around
    jonas_kirilla
    Posts: 18 from 2003/12/29
    From: Uppsala, Sweden
    This one's informative and succint:

    The HTTP Pocket Reference
    http://www.oreilly.com/catalog/httppr/

    /Jonas.
  • »10.03.04 - 19:53
    Profile Visit Website
  • Paladin of the Pegasos
    Paladin of the Pegasos
    TheMagicM
    Posts: 1220 from 2003/6/17
    thanks for all the replies!


    btw, it doesnt matter if I'm using Genesis, correct?
  • »10.03.04 - 20:04
    Profile Visit Website
  • Order of the Butterfly
    Order of the Butterfly
    Chain-Q
    Posts: 347 from 2003/10/12
    From: 1 AU, EU, DE/HU
    Yes, you can freely use Genesis as well. The calls you need are standardized, and the same in all TCP/IP stacks used nowadays, so you do it with Genesis, and it will work with MiamiDX, and vice-versa. And even on classic Amiga, if you compile your code for 68k as well.
    [.PegasosII/G4.:.Efika.:.Amiga2000/060.]
    [.Free Pascal Compiler MorphOS Port.]
    [.Hosting AmigaSpirit.hu.]
  • »10.03.04 - 22:02
    Profile Visit Website