Thread: Getting HTTP status of a site in C under Linux

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    2

    Exclamation Getting HTTP status of a site in C under Linux

    Hi

    I want to create an application to check if a site is active or inactive (homework for networking ). For that I need to connect to the ip at which the site resides and get the status. For that I create a socket with the IP and the port 80 and try to read an answer.
    First of all I want to ask if this is the correct course of actions.
    Second, I cannot connect with my socket to the designated IP and port 80 - it gives me: Connection refused. How can I connect to the server on which the site resides correctly.
    What message I should send to the server to get as response the status of the site or better an error code (404, 500, 200) from which I can see the status of the site.
    PS. I can use only the standard libraries on C under LINUX (it is a homework and I cannot use libraries made by someone else)

    Thank you in advance. Any help will be much appreciated.

  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
    Without seeing some code, who knows what you did wrong?
    Have you read beej yet?
    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
    Registered User
    Join Date
    Jan 2009
    Posts
    2
    Thank you Salem for the link.

    In fact I didn't wrote to much code except for trying to connect with a socket to the server.

    I need some samples of C code because I'm more of a PHP programmer and I don't know all the functions needed to do this others from the few I learned at the university.

  4. #4
    Chinese pâté foxman's Avatar
    Join Date
    Jul 2007
    Location
    Canada
    Posts
    404
    If the connection is refused it might be because the host doesn't allow connection on port 80.
    Did you tried to connect normally to the site ?

    Do some search on the web and you'll find answers to your questions.

    Without writing code, you can use telnet to check the status of the host. Here's an example.
    Code:
    $ telnet www.ietf.org 80
    HEAD / HTTP/1.1
    Host: www.ietf.org
    
    HTTP/1.1 200 OK
    Date: Sat, 03 Jan 2009 19:47:20 GMT
    ...
    I hate real numbers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why Linux, for the average user?
    By Hunter2 in forum A Brief History of Cprogramming.com
    Replies: 32
    Last Post: 07-07-2006, 02:36 PM
  2. Port app from Windows to Linux
    By BobS0327 in forum Linux Programming
    Replies: 12
    Last Post: 02-12-2006, 02:35 AM
  3. Writing all HTTP requests from a website to a log file
    By goomyman in forum C# Programming
    Replies: 1
    Last Post: 07-29-2005, 09:18 AM
  4. linux wont boot
    By GanglyLamb in forum Tech Board
    Replies: 4
    Last Post: 02-13-2003, 04:04 PM
  5. Linux Under Windows
    By Strut in forum Linux Programming
    Replies: 3
    Last Post: 05-27-2002, 08:09 PM

Tags for this Thread