开发者

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 achi开发者_JAVA技巧eved 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


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜