简体   繁体   English

node.js requestify似乎什么也没做

[英]node.js requestify appears to do nothing at all

How do you troubleshoot this *? 您如何解决此*问题?

I'm sorry but it is SO disappointing when what should be simple things don't work the way it is claimed that they should. 很抱歉,当简单的事情不能像声称的那样起作用时,真让人失望。

Following is clipped directly from the projetc's gitHub site. 以下内容直接来自projetc的gitHub站点。

And if I do the same thing in PostMan - no problem. 如果我在PostMan中做同样的事情-没问题。

The first console.log() works. 第一个console.log()工作。 But NONE of the following get called. 但是以下任何一个都不会被调用。 It appears the the .then()s nor the .fail()s get called. 似乎会调用.then()或.fail()。 And if I add a catch() that too isn't called. 如果我添加一个catch(),也不会被调用。

I DO have requestify working in different node.js Express web applications without issue. 我确实要求在不同的node.js Express Web应用程序中正常工作。 This application is a node.js console application (a single .js file) which exists in the root of the Express web app. 该应用程序是Express Web应用程序根目录中的一个node.js控制台应用程序(单个.js文件)。

This .js file doesn't throw any errors when compiled or executed. 该.js文件在编译或执行时不会引发任何错误。

console.log("Let's begin");

/* appears to  do nothing */
requestify.get('https://www.example.com/api/get.json')
.then(function (response) {
    console.log('response', response.getBody());
})
.fail(function (response) {
        console.log('response Error', response.getCode());
    })
;


/* also appears to do nothing */
requestify.request('https://www.example.com/api/get.json', {
    method: 'GET'
})
.then(function(response) {
    console.log('responsebody', response.getBody());
    console.log('response headers',response.getHeaders());
    console.log('responseheader Accept', response.getHeader('Accept'));
    console.log('response code', response.getCode());
    console.log('responsebody RAW', response.body);
    })
.fail(function (response) {
        console.log('response Error', response.getCode());
    })
;

2 things, 2件事,

  1. You didn't require requestify, 您不需要requestify,
  2. You have 3 single quotes in your first console log. 您的第一个控制台日志中有3个单引号。 So that's sure to break;. 因此,这肯定会破坏;。

 'use strict'; const requestify = require('requestify'); /* appears to do nothing */ requestify.get('https://www.example.com/api/get.json') .then(function (response) { console.log('response', response.getBody()); }) .fail(function (response) { console.log('response Error', response.getCode()); }) ; /* also appears to do nothing */ requestify.request('https://www.example.com/api/get.json', { method: 'GET' }) .then(function(response) { console.log('responsebody', response.getBody()); console.log('response headers',response.getHeaders()); console.log('responseheader Accept', response.getHeader('Accept')); console.log('response code', response.getCode()); console.log('responsebody RAW', response.body); }) .fail(function (response) { console.log('response Error', response.getCode()); }) ; 

I can't say exactly what it is but requestify isn't working a console app. 我无法确切地说出它是什么,但requestify无法正常运行控制台应用程序。 But is working on the first try having migrated to a webapp. 但是正在尝试迁移到Webapp的首次尝试。

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

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