We help IT Professionals succeed at work.
Get Started

HttpOpenRequest WinINet - invalid URl with port 993? (C++)

1,758 Views
Last Modified: 2013-12-14
Hi,

I'm trying to use HttpOpenRequest to post to a web service on port 993 (code below). Unfortunately I always get error code 12005 - invalid URL. Why is that? On other ports like 80 or 443 I get other errors like 'can not connect'. I know 993 is the imaps port but it's not blocked - I see that in netstat. Why can't I open a request to this port?

Thanks!


-------------------------------------
#include <windows.h>
#include <wininet.h>
#include <stdio.h>

#pragma comment(lib, "wininet.lib")

int main(int argc, char *argv[])
{
      HINTERNET hInternet = NULL;
      HINTERNET hConnect = NULL;
      HINTERNET hRequest = NULL;
      DWORD size  = 0;
      BOOL bRetVal = TRUE;
      
      hInternet = InternetOpen(TEXT("slim-jim-proxy"),
      INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);

      if (hInternet == NULL)
      {
            printf("hInternet == NULL\n");
            //return FALSE;
      }

      hConnect = InternetConnect(hInternet, TEXT("localhost"), 993, NULL,
      NULL, INTERNET_SERVICE_HTTP, 0, 0);

      if (hConnect == NULL)
      {
        printf("hConnect == NULL\n");
        InternetCloseHandle(hInternet);
        //return FALSE;
      }

    DWORD errorCode = 0;


      hRequest = HttpOpenRequest(hConnect, TEXT("POST"),
      TEXT(""), TEXT("HTTP/1.1"), NULL, NULL,
      INTERNET_FLAG_NO_CACHE_WRITE |
      INTERNET_FLAG_NO_COOKIES |
      INTERNET_FLAG_NO_AUTH |
      INTERNET_FLAG_SECURE
      | INTERNET_FLAG_IGNORE_CERT_CN_INVALID
      | INTERNET_FLAG_IGNORE_CERT_DATE_INVALID, NULL);
      //TEXT("gmail"), TEXT("HTTP/1.1"), NULL, NULL,
      //INTERNET_FLAG_RELOAD, NULL);

      errorCode = GetLastError();
      printf("errorCode: %d\n", errorCode);
      if (hRequest == NULL)
      {
            printf("hRequest == NULL\n");
            InternetCloseHandle(hConnect);
            InternetCloseHandle(hInternet);

            //return FALSE;
      }


      


      InternetCloseHandle(hRequest);
      InternetCloseHandle(hConnect);
      InternetCloseHandle(hInternet);

      system("pause");

}
Comment
Watch Question
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 8 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE