鍍金池/ 問答/數(shù)據(jù)庫  HTML/ 用node的request方法去慕課網(wǎng)的視頻課程里模擬評(píng)論,發(fā)現(xiàn)一直失敗,求解答

用node的request方法去慕課網(wǎng)的視頻課程里模擬評(píng)論,發(fā)現(xiàn)一直失敗,求解答

代碼如下:

var http = require('http')
var querystring = require('querystring')

var postData = querystring.stringify({
    'content': '收貨很大的啊!',
    'cid': '348'
})

var options = {
    hostname: 'www.imooc.com',
    port: 80,
    path: '/course/docomment',
    method: 'POST',
    headers: {
        'Accept': 'application/json, text/javascript, */*; q=0.01',
        'Accept-Encoding': 'gzip, deflate, br',
        'Accept-Language': 'zh-CN,zh;q=0.9',
        'Connection': 'keep-alive',
        'Content-Length': postData.length,
        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
        'Cookie': 'imooc_uuid=6c55c3b0-3c94-4f53-a44e-6b6b7b105293; imooc_isnew_ct=1510198466; UM_distinctid=15fc3e34db2693-01d3aef2b9e856-5b44271d-1fa400-15fc3e34db39cd; CNZZDATA1261110065=1876606176-1510817537-https%253A%252F%252Fwww.baidu.com%252F%7C1515481428; imooc_isnew=2; loginstate=1; apsid=ZhM2VhNmI3MDM4ZjViMjFkZDg0MWIxNGYwNDlkZGUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMjA5MDY5NAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA5ODY5OTI0ODRAcXEuY29tAAAAAAAAAAAAAAAAAAAAADc2ZjY0Y2MwMWZjZTA1NDBlYWU2YjE0Nzg1ZTU0MGE0d5aoWneWqFo%3DMT; CNZZDATA1273093942=1311350390-1520995090-%7C1520995090; PHPSESSID=9jo6kjqo4lrk4r06sfs0uokju1; IMCDNS=0; Hm_lvt_f0cfcccd7b1393990c78efdeebff3968=1521029597,1521461698,1521552907,1522654733; Hm_lpvt_f0cfcccd7b1393990c78efdeebff3968=1522655634; cvde=5ac1ddfbb8ac7-37',
        'Host': 'www.imooc.com',
        'Origin': 'https://www.imooc.com',
        'Referer': 'https://www.imooc.com/comment/348',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36',
        'X-Requested-With': 'XMLHttpRequest'
    }
}

//構(gòu)造一個(gè)request
var req = http.request(options, function(res) {
    console.log('Status:' + res.statusCode)
    console.log('headers:' + JSON.stringify(res.headers))

    res.on('data', function(chunk) {
        console.log(Buffer.isBuffer(chunk))
    })

    res.on('end', function() {
        console.log('評(píng)論完畢')
    })
})

req.on('error', function(e) {
    console.log('Error' + e.message)
})
//將請(qǐng)求的數(shù)據(jù)寫到頭部,用write方法
req.write(postData)
//結(jié)束請(qǐng)求
req.end()

發(fā)現(xiàn)一直報(bào)錯(cuò)。。。Unsupported Request Method and Protocol。
Squid does not support all request methods for all access protocols.
For example, you can not POST a Gopher request.

回答
編輯回答
單眼皮

協(xié)議不同,HTTP 換成 HTTPS

2017年2月7日 00:35
編輯回答
毀與悔

這不是你代碼的錯(cuò),是squid代理的問題。

2018年5月13日 21:42