Thread: Sending an http POST request

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    10

    Sending an http POST request

    I need to query a web server via http POST or GET and retrieve the result to a string in my program for parsing. It needs to be lightweight and compatible with at least windows and linux. I have already implemented a basic TCP socket interface in my program so i'm hoping it can build on that.

    Any ideas?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Do you know how to do a HTTP POST request with telnet?
    If you know that, you can do it easily by just sending the right data to the server...
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  4. #4
    Registered User
    Join Date
    Nov 2006
    Posts
    10
    Quote Originally Posted by maxorator
    Do you know how to do a HTTP POST request with telnet?
    If you know that, you can do it easily by just sending the right data to the server...
    That would be by far the best option. I want to avoid including external libraries if possible and since I already have the fundamentals of tcp socket communications I could easily incorporate it into my code.

    Only problem is I dont know how. I imagine i'd start by connecting to the http web server and then send some data, then listen for a response. But what format should the data take?

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    So what's your real question?

    > But what format should the data take?
    Goto www.rfc-editor.org and search out the RFC's which specify the HTTP protocol.

    Have a nice long read, scratch your head a lot, then decide whether using a pre-written library is a viable option.

    Whilst in principle it's just a matter of figuring out which bytes to send (easy, since you've already done that), there is a hell of a lot of detail.
    But if you're just trying to do just one or two specific things, you can get away with less.

    The first step is to download ethereal and use it to observe what real HTTP clients and your program do.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    > Have a nice long read, scratch your head a lot, then decide whether using a pre-written library is a viable option.

    I sooo echo this!

    There is no beating a library where people smarter than us have already done the dirty work and left us with a nice, clean, simple set of functions, classes and other toys.

    It's a matter of objectives and objectivity jaxen. You have to be objective about your objectives. (I'm enjoying this word play ). What is your objective?

    To send a HTTP POST/GET request and intepret the results? Or,
    To learn about HTTP POST/GET data format and semantics?

    Until the second starts interesting you, you should focus on your real objective. The first.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. bad performance for the code to send Http request
    By Checker1977 in forum C# Programming
    Replies: 8
    Last Post: 08-20-2008, 07:16 PM
  2. HTTP Methods POST AND GET "DATA"
    By bhupesh.kec in forum C Programming
    Replies: 4
    Last Post: 06-05-2008, 12:35 PM
  3. I Need A Example For Http Post
    By rjhome in forum C Programming
    Replies: 5
    Last Post: 02-17-2002, 10:49 AM
  4. 40 post drop
    By gamegod3001 in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 10-12-2001, 12:14 PM