1

In my C# code I want to use InternetQueryOption which is defined in MSDN such as:

BOOL InternetQueryOption(
  __in     HINTERNET hInternet,
  __in     DWORD dwOption,
  __out    LPVOID lpBuffer,
  __inout  LPDWORD lpdwBufferLength
);

In my C# code I wrote:

    [DllImport("wininet.dll", SetLastError = true)]
            static extern bool InternetQueryOption(
            IntPtr hInternet, 
            uint dwOption, 
            IntPtr lpBuffer, 
            ref int lpdwBufferLength);

My C++ code:

...
HINTERNET hRequest = HttpOpenRequest(hConnect, "POST","/BM-Login/auth-cup", NULL, NULL, accept, secureFlags, 0);
    DWORD dwFlags;
    DWORD dwBuffLen = sizeof(dwFlags);

    InternetQueryOption (hRequest, INTERNET_OPTION_SECURITY_FLAGS,
            (LPVOID)&dwFlags, &dwBuffLen);

    dwFlags |= SECURITY_FLAG_IGNORE_UNKNOWN_CA;
      dwFlags |= SECURITY_FLAG_IGNORE_REVOCATION;
      dwFlags |= SECURITY_FLAG_IGNORE_CERT_DATE_INVALID;
      dwFlags |= SECURITY_FLAG_IGNORE_CERT_CN_INVALID | SECURITY_FLAG_IGNORE_WRONG_USAGE;

    InternetSetOption (hRequest, INTERNET_OPTION_SECURITY_FLAGS,
                            &dwFlags, sizeof (dwFlags) );
...

How to write the same in C#? Thanks. (Sorry for my very bad English)

amaranth
  • 979
  • 2
  • 22
  • 40

1 Answers1

1

I'd recommend using manged code for this instead of doing this via interop. Have a look at the WebRequest Class. Also, have a look at my answer to the stackoverflow question C# https login and download file for a working example of how this class can be used.

Community
  • 1
  • 1
JamieSee
  • 12,696
  • 2
  • 31
  • 47