Hey guys, I'm trying to make a program that checks a specific internet address and gives me back the HTTP Status Code, I have to do it in C because it's a school project.
I'm using the Cygwin compiler on a Windows 7 (64-bit version)
I've searched Google for some good examples, but all I come across is C# and C++ codes.
This is the code I've found that makes the much sense to me but as far as I know, this has nothing to do with C.
Any suggestions / code examples I can cast my eyes on?
As for suggestions, what the full purpose of this is, is to check if a specific webpage is a valid internet link.
Two examples:
www.google.com/services/ is a valid link (This page exist)
www.google.com/something/ is not a valid link (This page do not exist)
I've also tried it with this code:
But this code, is only capable of contacting domain addresses which just isn't enough.
Thanks in advance
I'm using the Cygwin compiler on a Windows 7 (64-bit version)
I've searched Google for some good examples, but all I come across is C# and C++ codes.
Code:
HttpWebRequest HttpWReq = (HttpWebRequest)WebRequest.Create("http://www.google.com/services/"); HttpWebResponse HttpWResp = (HttpWebResponse)HttpWReq.GetResponse(); Response.Write(HttpWResp.StatusCode);
Any suggestions / code examples I can cast my eyes on?
As for suggestions, what the full purpose of this is, is to check if a specific webpage is a valid internet link.
Two examples:
www.google.com/services/ is a valid link (This page exist)
www.google.com/something/ is not a valid link (This page do not exist)
I've also tried it with this code:
Code:
#include <stdio.h> #include <string.h> #include <sys/types.h> #include <sys/socket.h> #include <netdb.h> #include <arpa/inet.h> void tjeklinkonline(char *linkIND) { struct addrinfo hints, *res, *p; int status; char ipstr[INET6_ADDRSTRLEN]; // Determines IP-type and Socket memset(&hints, 0, sizeof hints); hints.ai_family = AF_UNSPEC; // AF_INET or AF_INET6 to force version hints.ai_socktype = SOCK_STREAM; //Pings net address, and write response if ((status = getaddrinfo(linkIND , NULL, &hints, &res)) != 0) { fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(status)); printf("Not a Valid Link \n"); } else { printf("Valid Link\n"); } freeaddrinfo(res); // free the linked list } // End of function int main(void) { char link[40] = "www.google.com"; char link2[40] = "www.google.com/services/"; tjeklinkonline(link2); return 0; }
Thanks in advance
Comment