42 lines
1.9 KiB
C
42 lines
1.9 KiB
C
/* dev_repro2.c — 真机 dump weapi account/get 响应的真实分段(Content-Length/chunked/body_len)。
|
|
* 用大缓冲 64KB,避免 -11 FULL;打印解析出的 status/content_length/chunked/body_len。
|
|
*/
|
|
#include "ncm.h"
|
|
#include "ncm_req.h"
|
|
#include "ncm_http.h"
|
|
#include "ncm_common.h"
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
int main(int argc, char **argv) {
|
|
const char *data_dir = argc > 1 ? argv[1] : "/usr/data/mnt/sd_0/MeowData/dev.player.ncm/data";
|
|
const char *cacert = argc > 2 ? argv[2] : "/usr/data/mnt/sd_0/MeowAPPs/dev.player.ncm/cacert.pem";
|
|
|
|
ncm_ctx_t ctx;
|
|
ncm_ctx_init(&ctx, data_dir);
|
|
printf("device_id=%s cookie_len=%zu\n", ctx.device_id, strlen(ctx.cookie));
|
|
ncm_http_set_verify_default(1, cacert);
|
|
|
|
char body[NCM_REQ_BODY_MAX], hdrs[NCM_REQ_HDRS_MAX], url[NCM_REQ_URL_MAX];
|
|
int rc = ncm_req_build(ctx.device_id, ctx.cookie, "/api/w/nuser/account/get", "{}",
|
|
NCM_CRYPT_WEAPI, body, sizeof body, hdrs, sizeof hdrs, url, sizeof url);
|
|
if (rc != 0) { printf("req_build rc=%d\n", rc); return 1; }
|
|
printf("URL=%s\nbody_len=%zu hdrs_len=%zu\n", url, strlen(body), strlen(hdrs));
|
|
|
|
ncm_http_req_t req; memset(&req, 0, sizeof req);
|
|
req.url = url; req.method = "POST"; req.body = body; req.body_len = strlen(body);
|
|
req.extra_hdrs = hdrs; req.verify_ca = NCM_HTTP_VERIFY_DEFAULT; req.timeout_ms = 15000;
|
|
|
|
static char respbuf[65536];
|
|
ncm_http_resp_t resp;
|
|
long t0 = (long)ncm_now_ms();
|
|
rc = ncm_http_request(&req, respbuf, sizeof respbuf, &resp);
|
|
long dt = (long)ncm_now_ms() - t0;
|
|
printf("http_request rc=%d elapsed_ms=%ld\n", rc, dt);
|
|
printf("status=%d content_length=%zu chunked=%d\n", resp.status, resp.content_length, resp.chunked);
|
|
printf("headers_len=%zu\n", resp.headers_len);
|
|
printf("body_len=%zu\n", resp.body_len);
|
|
if (resp.body_len) printf("body_head:\n%.*s\n", (int)(resp.body_len < 800 ? resp.body_len : 800), resp.body);
|
|
return 0;
|
|
}
|