简体   繁体   English

使用 Node.js 访问特定网页时的 400 状态代码。 从我的浏览器点击同一个网页时出现 200 状态代码。 是什么赋予了?

[英]400 status code when using Node.js to hit a specific web page. And a 200 status code when hitting same web page from my browser. What gives?

Web URL in question: https://www.theroyalamerican.com/schedule有问题的网址: https : //www.theroyalamerican.com/schedule

I am building a node.js script to scrape the web page above using the request-promise package (which grabs the page's html for me).我正在构建一个 node.js 脚本来使用request-promise包(它为我抓取页面的 html)抓取上面的网页。 Unfortunately, when I run my code, it gives me a 400 status code from Squarespace (the apparent host of this site).不幸的是,当我运行我的代码时,它给了我来自 Squarespace(该站点的明显主机)的400 状态代码

Strangely, when I browse to the same URL in my web browser, I can pull it up with no problem at all - 200 status code .奇怪的是,当我在 Web 浏览器中浏览到相同的 URL 时,我可以毫无问题地将其拉起 - 200 status code

I do not have this problem, where my node script and web browser seem to mismatch, with any other web pages.我没有这个问题,我的节点脚本和网络浏览器似乎与任何其他网页不匹配。 Curious what's going on here...很好奇这里发生了什么......

const rp = require('request-promise');
const $ = require('cheerio');
const url = 'https://www.theroyalamerican.com/schedule';

rp(url)
  .then(function(html) {
     console.log(html);
   })
  .catch(function(err) {
     console.log(err);
    //handle error
  });

Check all the headers that are being sent when you request this page in browser vs in Node.js.检查在浏览器和 Node.js 中请求此页面时发送的所有标头。 Probably some header affects the possible response (like Content-Type maybe? or maybe try passing Origin header)可能某些标头会影响可能的响应(例如Content-Type可能?或者尝试传递Origin标头)

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

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