eramitmodi
eramitmodi

Reputation: 31

C++ : Getting HTTP status code from a URL

I am working on a application where-in i have to hit a URL and get the HTTP status code returned from that URL. Currently I am using WININET functions to achieve this. The code to achieve this:

hOpen = InternetOpenA("MYAPP", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0); hFile = InternetOpenUrlA(hOpen, url.c_str() , NULL, 0,INTERNET_FLAG_RELOAD, 0); HttpQueryInfoA(hFile,HTTP_QUERY_STATUS_CODE,(void*)buffer,&dwBufLen,NULL);

I did some checks to see the performance and i can see that on average a hit is taking about 300 milli-seconds. As i will be making multiple hits, the total time comes to about 8-10 sec which is slowing down the whole application.

Also the same is achieved on MAC is about 100 milli-seconds or so(i am using COCOA).

So are there any other APIs on WIN which i can use to get this faster?

Thanks in advance, Amit

Upvotes: 3

Views: 1532

Answers (2)

jpyllman
jpyllman

Reputation: 305

libcurl is another option. It is actually platform independent. The thing that you might not like with this library is that you will need some extra DLLs.

Upvotes: 2

Murray
Murray

Reputation: 690

WinHTTP is the other major Win32 HTTP API. It is designed more for servers and clients without UI and thus may be faster.

Upvotes: 1

Related Questions