一、打开chrome按f12,点击右上角的“关注”按钮,抓包位置如下:
(图1 follow接口)
二、follow接口分析
1、请求地址
https://edith.xiaohongshu.com/api/sns/web/v1/user/follow
2、请求方法:
POST
3、请求头:
:authority:
edith.xiaohongshu.com
:method:
POST
:path:
/api/sns/web/v1/user/follow
:scheme:
https
Accept:
application/json, text/plain, */*
Accept-Encoding:
gzip, deflate, br, zstd
Accept-Language:
zh-CN,zh;q=0.9
Content-Length:
45
Content-Type:
application/json;charset=UTF-8
Cookie:
{.........此处省略..............}
Origin:
https://www.xiaohongshu.com
Referer:
https://www.xiaohongshu.com/
Sec-Ch-Ua:
"Google Chrome";v="123", "Not:A-Brand";v="8", "Chromium";v="123"
Sec-Ch-Ua-Mobile:
?0
Sec-Ch-Ua-Platform:
"Windows"
Sec-Fetch-Dest:
empty
Sec-Fetch-Mode:
cors
Sec-Fetch-Site:
same-site
User-Agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36
X-B3-Traceid:
c47c9349e64fd39d
X-S:
XYW_eyJzaWduU3ZuIjoiNTEiLCJzaWduVHlwZSI6IngxIiwiYXBwSWQiOiJ4aHMtcGMtd2ViIiwic2lnblZlcnNpb24iOiIxIiwicGF5bG9hZCI6IjQwMGQwNzU2NmQ2MjE0MjU0NTZkY2RkNTZlOGRlMjU4ZTVmOWZjOGQxODU5ZDllODk2MjMxMzA2OGY1NmU0MjQ3NTQ2NGJjNzNlNmU1ZWMyZjg4NTJhNzdhYzcxMTNkYWM5ZTNiZmRhMWZhYTFlYjkwZDc0YWEzMWI1NGM3MmNkMGQ3NGFhMzFiNTRjNzJjZGFjNDg5YjlkYThjZTVlNDhmNGFmYjlhY2ZjM2VhMjZmZTBiMjY2YTZiNGNjM2NiNTUzZjAxZTk0Nzg2NWIwZGE5MzU0MGFkNzFmODhhNmViNDRlYmQyOGZiN2IxNGQzMWJjNzRjNGJhNjI1NDRmMTM4Y2YwN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L9qAP7zg+Q40pA+fP98/mc4FbQcFkSPgbF4DkS+obQyrD3a/PMqA8U8Bp3JDkS8oHIqM+n4ozQypmaa/+84nRc4BbQcMbnaLpSqA+PzBYFpLEA8dbFqLSi/oQyLozaPfPAqMSIcnpgLo4TJMm74FS9nSYQypmFGMm7Ggbc47pQ2rkA8bkt8/bM4FEIqgz9aLp32nQc4b4QP7QC8FQawrS3Po+88rEA8fEw8pzn47zF4gzHaLLFqDS98Bph4g4aanSSqAmQp0SQ2op7Gp+n/FSeqnRQcFESyMm78okl4rkzLocha/+MzLSiPo+h8/mSygbFLMkyLDpQPF4czM8FqnMn4eYQPF4na/P3GDSbqgpQy9pApSSS8nTgn0bEpdzUa/+jP9Qn4bbSpdzLanYS8/8sqS+QyLqMz9Rd8n8l4rpyLoz1JL8LJf4AqBTQynTBNM87/DSk+gPlGAYoanTBJgkc4BkQyb8cwob78sRM49EQypQmagYUprDAtAQPLo4kanTc2DSbPoPApd43/M4VcFSi/bkQc94A8eZI8/bl4BkQ2b83anYinrl8p78QcAz8/BMzyrSh4fpfGFbAzbmFaDSkP9pLqg4OanVF4rDAa9p8LozsaL+T+gmc4McjNsQhwaHCP/ZFP0HE+APIPUIj2erIH0ilPALAKc==
X-T:
1713252619968
4、请求数据体
{"target_user_id":"59391d446a6a6960704f16b1"}
5、请求成功返回:
{"code":0,"success":true,"msg":"成功","data":{"fstatus":"follows"}}
三、nodejs调用接口代码
const https = require('node:https');
const fs = require("fs");
const os = require("os");
//----------------------------------------------调用模块初始化----------------------------------------------------
const m_common_data = require('./x_s_common.js');//X-S-Common签名
const m_xs_data = require('./xs.js');//X-S签名
const m_proxy = require('./proxy.js');
const agent=m_proxy.get_agent();
//mode by byc6352 or metabycf in 2024-01-05
exports.set_follow=set_follow;//target_user_id=被关注用户id a1=从cookie提取的 web_session=从cookie提取的
async function set_follow(target_user_id,web_session,a1){let cookie=`abRequestId=b5675107-257c-5e9e-9bfe-157d0dc56027; webBuild=3.11.3; xsecappid=xhs-pc-web;a1=${a1};webId=4f4e47c26fec73469f2a0a1b36b59b49;web_session=${web_session}; websectiga=6169c1e84f393779a5f7de7303038f3b47a78e47be716e7bec57ccce17d45f99; sec_poison_id=30196e44-925f-4243-86da-685cafcc09e5;gid=yYDq8j0dy2M8yYDq8j0fW003JWv0DIMSFAY0kJMTIACS3928S0hi80888qKj8WW8DJyfKWW`;let url="https://edith.xiaohongshu.com/api/sns/web/v1/user/follow";let path=url.replace("https://edith.xiaohongshu.com","");let data={target_user_id: target_user_id};let data_str=JSON.stringify(data);let o=await m_xs_data.get_xs(path,data_str,a1);var xs=o["X-s"];var xt=o["X-t"];let x_common=m_common_data.get_common(a1,xt,xs);let traceid=m_common_data.get_traceid();let headers={"Connection":"close","authority":'edith.xiaohongshu.com',"method":'POST',"path":'/api/sns/web/v1/user/follow',"scheme":'https',"Accept":'application/json, text/plain, */*',//"Accept-Encoding":'gzip, deflate, br',"Accept-Language":'zh-CN,zh;q=0.9',"Content-Length":'45',"Content-Type":'application/json;charset=UTF-8',"Cookie":cookie,//"Origin":'https://www.xiaohongshu.com',"Referer":'https://www.xiaohongshu.com/',"Sec-Ch-Ua":'"Not A(Brand";v="99", "Google Chrome";v="121", "Chromium";v="121"',"Sec-Ch-Ua-Mobile":'?0',"Sec-Ch-Ua-Platform":'"Windows"',"Sec-Fetch-Dest":'empty',"Sec-Fetch-Mode":'cors',"Sec-Fetch-Site":'same-site',"User-Agent":'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36',"X-B3-Traceid":traceid,//'0a781c1de7825c27',"X-S":xs,//'XYW_eyJzaWduU3ZuIjoiNTEiLCJzaWduVHlwZSI6IngxIiwiYXBwSWQiOiJ4aHMtcGMtd2ViIiwic2lnblZlcnNpb24iOiIxIiwicGF5bG9hZCI6ImMwNjkwZjhiMmJjNWJlYzZjODFiYTBkMGE5NzYzM2E1YTg3ODgyYTU3ZTM4NDJkZ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m8pFpC/p4QPLEo//++JLE3/L4zPFEozfY+2D8k/SzayDECafkyzF8x/Dzd+pSxJBT8pBYxnSznJrEryBMwzF8TnnkVybDUnfk+PS8i/nkyJpkLcfS+ySDUnpzyyLEo/fk+PDEk/Szp2pSxzfTypFFF/pz32SSCLg4wyDM7/FziJrhUzg4ypr8infk02LMoz/mwPS8inD4+2rECL/QyzrrA/p4QPFMTng482DQT/dk3PrFUp/+8yDbE/gkpPrEgp/z+pr8xnDzzPFEonfTyzFMh/Fzz+LMLp/QwyDrMnSztJpSga/p82SkVnfkQPLRrGAQyzrET/D48+LMxyAmwpMki/F4b2rMga/bwpFLAngk3PpSgzgS+pMQTnfkwyLMx87YOpBYTnSzaJpDU/flyzrpEnS4z2bSga/Q8pFMEnSz34FhU/fk+zrFF/fks',"X-T":xt//'1709452415373',}const options = {hostname: 'edith.xiaohongshu.com',port: 443,path: path,method: 'POST',headers: headers}if(agent!==undefined)options.agent = agent;let req = https.request(url,options, (res) => {console.log(`STATUS: ${res.statusCode}`);console.log(`HEADERS: ${JSON.stringify(res.headers)}`);res.setEncoding('utf8');var body="";res.on('data', (chunk) => {body=body+chunk;});res.on('end', () => {try {console.log(body);}catch (e){console.error(e);}});res.on('close', () => {console.log("close");});});req.on('error', (e) => {console.error(`problem with request: ${e.message}`);});req.write(data_str,'utf8');req.end();}
第三方调用接口:
http://helpnow.top:8087/xhs/follow?key=234181402307&target_user_id=被关注用户id&a1=从cookie提取的&web_session=从cookie提取的
四、follow接口调用成功
(图2follow接口调用成功)
6Zeu6aKY5ZKo6K+i77yadng6YnljNjM1MiBvciBtZXRhYnljZjtRUTozOTg0ODg3Mjt0ZWxlZ3JhbTpieWMwMQ==(base64解码)