简体   繁体   English

CookieJars使用请求承诺获取所有cookie,nodeJS

[英]CookieJars obtaining all cookies, nodeJS using request-promise

I am struggling to successfully make a request using request-promise npm on a site that requires a cookie to view or for the request to be successful. 我正在努力在需要cookie才能查看或成功的站点上使用request-promise npm成功地发出请求。

Henceforth, I have looked into cookieJars in order to store all those that are given in the repsonse after the request has been done. 从此以后,我研究了cookieJars,以便在请求完成后存储在响应中给出的所有内容。

const rp = require("request-promise")
var cookieJar = rp.jar()
function grabcfToken(){
let token  = ""
let options = {
    url : 'https://www.off---white.com/en/GB',
    method: "GET",
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36',
    resolveWithFullResponse : true
}

rp(options)
    .then((response)=>{
        console.log(response)
    }) 
    .catch((error)=>{
        console.log(error)
    })

} }

Can someone tell me why the request isn't successfully going through? 有人可以告诉我为什么请求无法成功处理吗? How do I apply the cookies that I initially get before being timed out. 如何应用我在超时之前最初获得的cookie。

const rp = require("request-promise")
var cookieJar = rp.jar()
function grabcfToken(){
let token  = ""
let options = {
    url : 'https://www.off---white.com/en/GB',
    method: "GET",
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36',
    resolveWithFullResponse : true,       
   jar: cookieJar
}

rp(options)
    .then((response)=>{
        console.log(response)
    }) 
    .catch((error)=>{
        console.log(error)
    })
}

If you're asking about including your jar which you filled with the cookies from the request to be sent to across you have to add jar: cookiejar as pasrt of your options object before sending it. 如果您要从请求中发送的请求中包含要用cookie填充的jar,则必须在发送之前添加jar:cookiejar作为options对象的pasrt。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM