1

I'm web scraping some https website. This is my code.

hh.OpenHttp AddressOf InternetStatusCallback, "MY WEBSITE", "GET", 443, "/search/searchResult"
...
Private ctx As LongPtr
...
'OpenHttp Function
openRequestHandle = HttpOpenRequest(connectHandle, mMethod, mUrl, vbNullString, vbNullString, vbNullString, INTERNET_FLAG_RELOAD Or INTERNET_FLAG_NO_CACHE_WRITE, VarPtr(ctx))

And I got this.

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
Reason: You're speaking plain HTTP to an SSL-enabled server port.<br />
Instead use the HTTPS scheme to access this URL, please.<br />
<blockquote>Hint: <a href="MY WEBSITE"><b>MY WEBSITE</b></a></blockquote></p>
</body></html>

The website is not mine so I can't edit website. I can just only edit my code.

Any ideas?

NeW
  • 49
  • 1

1 Answers1

0

You need to specify a secure connection flag when you call this:

void HttpOpenRequestA(
  HINTERNET hConnect,
  LPCSTR    lpszVerb,
  LPCSTR    lpszObjectName,
  LPCSTR    lpszVersion,
  LPCSTR    lpszReferrer,
  LPCSTR    *lplpszAcceptTypes,
  DWORD     dwFlags,
  DWORD_PTR dwContext
);

On MS:

https://learn.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-httpopenrequesta

INTERNET_FLAG_SECURE Uses secure transaction semantics. This translates to using Secure Sockets Layer/Private Communications Technology (SSL/PCT) and is only meaningful in HTTP requests.

And on Stack:

How to send HTTPS request using WinInet?

tcarvin
  • 10,715
  • 3
  • 31
  • 52
  • Thanks. so I use this now: openRequestHandle = HttpOpenRequest(connectHandle, mMethod, mUrl, vbNullString, vbNullString, vbNullString, INTERNET_FLAG_SECURE Or INTERNET_FLAG_IGNORE_CERT_CN_INVALID Or INTERNET_FLAG_IGNORE_CERT_DATE_INVALID, 0) But now, it doesn't work without any errors. Just infinity loading. What should I? – NeW Jun 25 '20 at 09:24
  • Why did you change the last parameter from `VarPtr(ctx)` to `0` ? – tcarvin Jun 25 '20 at 12:24
  • If I use VarPtr(ctx), then I get No Responding. – NeW Jun 26 '20 at 13:07