简体   繁体   中英

Why does cURL return correct value but not node-libcurl?

I am using cURL to fetch a website (which returns the error I want).

$ curl 'https://matchmaker.krunker.io/seek-game?hostname=krunker.io&region=us-ca-sv&game=SV%3A4jve9&autoChangeGame=false&validationToken=QR6beUGVKUKkzwIsKhbKXyaJaZtKmPN8Rwgykea5l5FkES04b6h1RHuBkaUMFnu%2B&dataQuery=%7B%7D

However, when I use the node-libcurl package in Node.JS, I get an error 1020. Why does this happen?

const { curly } = require('node-libcurl')
const url = 'https://matchmaker.krunker.io/seek-game?hostname=krunker.io&region=us-ca-sv&game=SV%3A4jve9&autoChangeGame=false&validationToken=QR6beUGVKUKkzwIsKhbKXyaJaZtKmPN8Rwgykea5l5FkES04b6h1RHuBkaUMFnu%2B&dataQuery=%7B%7D'

curly.get(url)
    .then(({ statusCode, data }) => console.log(statusCode, data))

1020 is not a curl error code, and a quick google search suggest 1020 is a common-ish firewall error for Cloudflare, ref https://community.cloudflare.com/t/error-1020-cannot-log-in-to-the-site-how-to-fix/71784

the most obvious difference for a server between a LIBcurl request and a curl request is that libcurl doesn't have an user-agent, but curl does, and it's not too uncommon to block requests lacking an user-agent (wikipedia.org is 1 example blocking requests lacking useragent),add an user-agent and try again.

curly.get(url,{userAgent:"imaginate's awesome curl script"})
    .then(({ statusCode, data }) => console.log(statusCode, data))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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