[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


How to handle error InternetConnect as connection timeout, server not found by using HTTP with wininet

Posted on 2007-10-17
Medium Priority
Last Modified: 2012-06-27
Hi Experts,
I have used HTTP connection in C++ as ::InternetOpen, ::InternetConnect to open and connect to server URL
BUT I don't know how to handle connection error as page not found, server not available,...
Because with my testing I use to connect with any URL, a invalide URL, a unavailble URL, I see InternetConnect return a NOT NULL connection.

So how can I know when server is not available, or server not found, or connect timeout,....
Can you give me a handle to handle errors by using HTTP with wininet

Question by:Mobinex
LVL 86

Accepted Solution

jkr earned 1000 total points
ID: 20101373
Usually, you'd do that like

HINTERNET hConn =  InternetConnect (
                hOpen,                      // InternetOpen handle
                "www.experts-exchange.com",             // Server  name
      INTERNET_DEFAULT_HTTP_PORT,// Default HTTP port - 80
                "",                         // User name
                "",                         //  User password
                INTERNET_SERVICE_HTTP,      // Service
      0,                          // Flags
      0                           // Context

if (hConn == NULL) { // error

    TCHAR buf[1024];
    DWORD dwError;

    MessageBox(NULL,buf,_T("InternetConnect() failed"), MB_OK);

Author Comment

ID: 20106302
But for server URL:   "www.experts-exchange.com"
Now, I replace to any URL as: www.testtest.com,   test, www.test.com.cn

It alway return NOT NULL, it means we can create connection.

So, when it will be NULL connection created?
And to handle server errors we will do at the time we send request?


Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question