This code download deflated XML document https://api.bilibili.com/x/v1/dm/list.so?oid=162677333
and save it to temp.Z
, which however seems broken. How is that?
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <wininet.h>
#pragma comment(linker, "/entry:\"mainCRTStartup\"")
#pragma comment(lib, "wininet.lib")
char *download(char *link, int *size)
{
int prealloc_size = 100000;
char *buf = malloc(prealloc_size);
DWORD num;
HINTERNET hinet;
HINTERNET hurl;
*size = 0;
hinet = InternetOpen("Microsoft Internet Explorer",
INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_INVALID_PORT_NUMBER);
hurl = InternetOpenUrl(hinet, link, NULL, 0, INTERNET_FLAG_NEED_FILE, 0);
while (TRUE == InternetReadFile(hurl, buf + *size, 1024, &num) && num > 0)
{
*size += num;
if (*size + 1024 > prealloc_size)
{
prealloc_size += prealloc_size / 2;
buf = realloc(buf, prealloc_size);
}
}
InternetCloseHandle(hurl);
InternetCloseHandle(hinet);
return buf;
}
int main(void)
{
char *link = "https://api.bilibili.com/x/v1/dm/list.so?oid=162677333";
FILE *f = fopen("temp.Z", "wb");
int siz;
char *dat = download(link, &siz);
fwrite(dat, 1, siz, f);
fclose(f);
free(dat);
return 0;
}
I tried Fiddler and it gets the same data, however, Fiddler can decode it, and says it is deflate.