/* host_repro.c — 复现 weapi login_status_check 断帧挂死/断头问题(宿主) * 用与 App 完全相同的 core 库路径:ncm_req_build(WEAPI) -> ncm_http_request。 * 用法: ./host_repro [cookie] */ #include "ncm.h" #include "ncm_req.h" #include "ncm_http.h" #include "ncm_common.h" #include #include static void dump_resp(const char *tag, const ncm_http_resp_t *r) { printf("---- %s ----\n", tag); printf("status=%d content_length=%zu chunked=%d ct=%s\n", r->status, r->content_length, r->chunked, r->has_content_type ? r->content_type : "(none)"); printf("headers(%zu):\n%s\n", r->headers_len, r->headers); printf("body_len=%zu\n", r->body_len); if (r->body_len) printf("body:\n%.*s\n", (int)r->body_len, r->body); } int main(int argc, char **argv) { const char *cookie = argc > 1 ? argv[1] : "__csrf="; const char *device = "68DFA27096B7A5DC2CB393C77D8C194FDC0459B743081D091EBD"; /* 同 App:用全局默认 CA(verify=1 + 系统CA) */ ncm_http_set_verify_default(1, NULL); char body[NCM_REQ_BODY_MAX], hdrs[NCM_REQ_HDRS_MAX], url[NCM_REQ_URL_MAX]; int rc = ncm_req_build(device, cookie, "/api/w/nuser/account/get", "{}", NCM_CRYPT_WEAPI, body, sizeof body, hdrs, sizeof hdrs, url, sizeof url); printf("req_build rc=%d\n", rc); if (rc != NCM_OK) return 1; printf("URL: %s\n", url); printf("BODY(len=%zu): %.*s\n\n", strlen(body), (int)strlen(body), body); printf("HDRS:\n%s\n\n", 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; char respbuf[8192]; 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("ncm_http_request rc=%d elapsed_ms=%ld\n", rc, dt); if (rc != NCM_OK) return 2; dump_resp("weapi account/get", &resp); return 0; }