簡體   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?

有問題的網址: https : //www.theroyalamerican.com/schedule

我正在構建一個 node.js 腳本來使用request-promise包(它為我抓取頁面的 html)抓取上面的網頁。 不幸的是,當我運行我的代碼時,它給了我來自 Squarespace(該站點的明顯主機)的400 狀態代碼

奇怪的是,當我在 Web 瀏覽器中瀏覽到相同的 URL 時,我可以毫無問題地將其拉起 - 200 status code

我沒有這個問題,我的節點腳本和網絡瀏覽器似乎與任何其他網頁不匹配。 很好奇這里發生了什么......

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
  });

檢查在瀏覽器和 Node.js 中請求此頁面時發送的所有標頭。 可能某些標頭會影響可能的響應(例如Content-Type可能?或者嘗試傳遞Origin標頭)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM