在两个PCF应用程序之间使用salies的API调用

时间:2017-06-29 18:55:43

标签: api

I am trying to write a PCF application that makes and API calls running in
another PCF application. I am using Salis framework. Below is my code

   ConnectApp: function(req,res){
   var https = require('https');
   var options = {hostname: 'hhgconnectcentral1.cfapps.io',
   port: 443,
   path: '/connection_requests/addConnection',
   method: 'GET',
   headers: {'accept': 'application/json'}
    };
   console.info('Options prepared:');
   console.info(options);

   https.request(options, function(response) {
   var responseData = '';
   response.setEncoding('utf8');
   response.on('data', function(chunk){
    responseData += chunk;
    });

  console.info(JSON.parse(responseData));

  response.once('error', function(err){
 // Some error handling here, e.g.:
 res.serverError(err);
 });

response.on('end', function(){
 try {
 // response available as `responseData` in `yourview`
  res.locals.requestData = JSON.parse(responseData);
  } catch (e) {
  sails.log.info('Could not parse response from options.hostname: ' + e);
  }
    res.view('yourview');
      });
     }).end();
     }

当我运行此代码时,我收到HTTP 502错误,我的应用程序崩溃并重新启动。   我在Logs中看到了以下内容。   2017-06-29T13:54:42.99-0400 [RTR / 5] OUT HHGPlayersCentral.cfapps.io - [2017-06-29T17:54:42.927 + 0000]“GET / player_requests / ConnectApp HTTP / 1.1”502 0 67“ - “”curl / 7.43.0“”10.10.2.20:31899“”10.10.148.95:61129“x_forwarded_for:”45.27.236.192“x_forwarded_proto:”https“vcap_request_id:”2c302365-9e76-40ba-668a-8ea05f70fd1d“response_time: 0.063139365 app_id:“247f9f87-9c61-44ee-a3d1-c06558ce9632”app_index:“0”x_b3_traceid:“26ded9881153c0ba”x_b3_spanid:“26ded9881153c0ba”x_b3_parentspanid:“ - ” 2017-06-29T13:54:42.99-0400 [RTR / 5] OUT 2017-06-29T13:54:42.99-0400 [APP / PROC / WEB / 0] ERR未定义:1 2017-06-29T13:54:42.99-0400 [APP / PROC / WEB / 0] ERR SyntaxError:意外的输入结束 2017-06-29T13:54:42.99-0400 [APP / PROC / WEB / 0] Object.parse的ERR(原生) 2017-06-29T13:54:42.99-0400 [APP / PROC / WEB / 0]在ClientRequest上的ERR。 (/home/vcap/app/api/controllers/ConnectAppRequestController.js:65:23) 2017-06-29T13:54:42.99-0400 [APP / PROC / WEB / 0] ClientRequest.g的ERR(events.js:260:16) 2017-06-29T13:54:42.99-0400 [APP / PROC / WEB / 0]在emitOne的ERR(events.js:77:13) 2017-06-29T13:54:42.99-0400 [APP / PROC / WEB / 0] ClientRquest.emit的ERR(events.js:169:7) 2017-06-29T13:54:42.99-0400 [APP / PROC / WEB / 0] HTTPParser.parserOnIncomingClient的ERR [as oncoming](_http_client.js:433:21) 2017-06-29T13:54:42.99-0400 [APP / PROC / WEB / 0] HTTPParser.parserOnHeadersComplete的ERR(_http_common.js:97:23)

我做错了什么?

0 个答案:

没有答案