Reputation: 21
I am currently building an http web client using sockets which gets a url as input and should perform the following task: Connect to the web server and save the response of the server in a file, and print the status code included in the http response.
I have completed the first part of writing in a file and I am having a problem with retrieving the status code. Is there a library or a function that could help me?
Upvotes: 2
Views: 1497
Reputation: 500457
The first line of the response is the status line, and is very easy to parse. It consists of the protocol version followed by a numeric status code and its associated textual phrase ("OK", "Not Found" etc).
For example:
HTTP/1.1 200 OK
The exact syntax and the list of valid codes is documented in RFC 2616 (section 6.1).
Upvotes: 2
Reputation: 981
You should use libcurl to perform the HTTP request.
And the function curl_easy_getinfo to get the HTTP code.
Upvotes: 2