【问题标题】:403 forbidden error on api urlapi url 上的 403 禁止错误
【发布时间】:2016-01-15 14:36:02
【问题描述】:

我正在使用 express.js 提交this api 的搜索查询。返回一个 json 对象。它包含一个指向 api 网站的图像 url。尝试获取图像时,返回 403 禁止。

这是一个示例url。它显示带有“拒绝访问”消息的 XML 错误。也许我需要在 url 中包含我的 api 密钥才能访问?如果是这样,我该怎么做?

这是我的代码:

var str = '';
var ingredients = null;
router.post('/', function(req,res){

 ingredients = req.body.ingredients; //get value of an <input> named 'ingredients'
 var callback = function(response){
 str = '';

 //another chunk of data has been recieved, so append it to `str`
 response.on('data', function (chunk) {
   str += chunk;
 });

 //the whole response has been recieved
 response.on('end', function () {
  var recipes = JSON.parse(str); //parse string to json
  res.render('home', {recipes: recipes}); //render view with required object
 });
}

var options = {
 host: "food2fork.com",
 path: "/api/search?key=[myKey]&q=" + ingredients
};

if(ingredients != null)
{
 http.request(options,callback).end();
 ingredients = null;
}

});

使用代码形式nodejitsu

【问题讨论】:

    标签: express http-status-code-403


    【解决方案1】:

    原来我打错了一个 HTML 车把图像元素:

    <img src={{image_url}}/>
    

    而不是

    <img src={{image_url}} />
    

    在网址末尾添加了一个额外的“/”并导致了问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-05
      • 2013-03-15
      • 2022-08-18
      • 2015-10-18
      • 1970-01-01
      • 2023-03-21
      • 1970-01-01
      相关资源
      最近更新 更多