Hi all.
I'm not used with windows programming at all to begin with. I'm more used with curl. However. I got to use Windows API this time, and I'm trying to get a hang of WinHttp but obviously get something wrong.
I wrote a little piece of code to go through the logic I need, but it segfaults. Can someone be so nice and point out where I'm going wrong?
Code:
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <windows.h>
#include <winhttp.h>
void http_callback(HINTERNET sess, DWORD_PTR ctx, DWORD sts, LPVOID info, DWORD infosz) {
printf("Status: 0x%08x\n", sts);
fflush(stdout);
}
int main(int argc, char **argv) {
int r;
HINTERNET sess;
HINTERNET conn;
HINTERNET requ;
sess = WinHttpOpen(
L"winhttp-test",
WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
WINHTTP_NO_PROXY_NAME,
WINHTTP_NO_PROXY_BYPASS,
WINHTTP_FLAG_ASYNC);
assert(sess);
r = (int) WinHttpSetStatusCallback(
sess,
(WINHTTP_STATUS_CALLBACK) http_callback,
WINHTTP_CALLBACK_FLAG_ALL_NOTIFICATIONS,
0);
assert(r != -1);
conn = WinHttpConnect(
sess,
L"www.google.com",
INTERNET_DEFAULT_HTTPS_PORT,
0);
assert(conn);
requ = WinHttpOpenRequest(
conn,
L"GET",
L"/index.html",
NULL,
WINHTTP_NO_REFERER,
WINHTTP_DEFAULT_ACCEPT_TYPES,
WINHTTP_FLAG_SECURE);
assert(requ);
r = WinHttpSendRequest(
requ,
WINHTTP_NO_ADDITIONAL_HEADERS,
0,
NULL,
0,
0,
0);
assert(r);
printf("Request sent!\n");
Sleep(10000);
return EXIT_SUCCESS;
}
The output of this program simply gets...
...and then it crashes.
Thanks.