Nodejs crawler, post requests to send request Playload format data.
This article takes the NetEase Cloud Classroom 2 POST request as the example, uses the request module to realize. Example 1
1. Address:
http://study.163.com/dwr/call/plaincall/MongoAttributesBean.obtainByRandomWithLimitTime.dwr?1521595046314
2. Request screenshot
From the image above you can see "Content-type" as "text/plain"; the way to send data: Request Payload,
The data is the normal line-wrapping string, not the JSON string.
3, Nodejs Code
Let request = require ("request");
Let URL = ' http://study.163.com/dwr/call/plaincall/mongoattributesbean.obtainbyrandomwithlimittime.dwr?${+new Date ()}`;
Let BODY = ' callcount=1\nscriptsessionid=\${scriptsessionid}190\nhttpsessionid=17faef42e6db4291819618913dc7f8da\ Nc0-scriptname=mongoattributesbean\nc0-methodname=obtainbyrandomwithlimittime\nc0-id=0\nc0-param0=string:spjdt \nc0-param1=number:7\nbatchid=1521527406791\n ';
Let opts = {
URL, method
: "POST",
headers: {"Content-type": "Text/plain"},
body:body
}
Request (opts, (E, B, D) => {
if (e) return Console.log (e);
Console.log (d);
})
4. Operation result
Can get the returned data normally. Example 2 1, Address: Http://study.163.com/p/search/studycourse.json This is the request address of the NetEase Cloud classroom search course. 2. Request screenshot
"Content-type" is "Application/json"; the way to send data is also: Request Payload,
The data format is a standard JSON string. 3, Nodejs Code
Let request = require ("request");
Let URL = ' Http://study.163.com/p/search/studycourse.json ';
Let BODY = {
activityid:0,
keyword: "Nodejs",
ordertype:5,
pageindex:1,
pagesize:50,
PriceType:-1,
relativeoffset:0,
searchtimetype:-1,
};
Let opts = {
URL, method
: ' POST ',
headers: {"Content-type": "Application/json"}, Body
: Json.stringify (body)
}
request (opts, (E, B, D) => {
if (e) return Console.log (e);
Console.log (d);
})
4. Operation result
This list is the result of the search. Unexpected Jinshi's blog: http://blog.csdn.net/zzwwjjdj1