· 7 years ago · Apr 16, 2018, 03:56 PM
1POST /oauth/token HTTP/1.1
2Host: connect.mail.ru
3Accept: */*
4Content-Length: 186
5Content-Type: application/x-www-form-urlencoded
6
7client_id=464119&
8client_secret=ac7fd2cc742c70a707cad3f6b2ca1c89&
9grant_type=authorization_code&
10code=000ff8627d2d79b60ebdaf004f9a68aa&
11redirect_uri=http://example.com/oauth/receiver
12
13var content="";
14 var post_data = querystring.stringify({
15 "client_id":id,
16 "client_secret":secret,
17 "grant_type":"authorization_code",
18 "code":req.query['code'],
19 "redirect_uri":redir
20 });
21 var options = {
22 hostname: 'connect.mail.ru',
23 path: "/oauth/token",
24 method: 'POST',
25 headers:
26 {
27 'Content-Type': 'application/x-www-form-urlencoded',
28 'Content-Length':post_data.length,
29 'Accept': '*/*'
30 }
31
32
33 };
34 b="";
35 var reqq = https.request(options, function(res) {
36 console.log("statusCode: ", res.statusCode);
37 console.log("headers: ", res.headers);
38
39 res.setEncoding('utf8');
40 res.on('data', function(d) {
41
42 b+=b;
43 });
44
45 res.on('end', function() {
46 console.log(b);
47 });
48
49 });
50
51 reqq.write(post_data);
52 reqq.end();