如何从返回的复杂响应中获取网址?

时间:2019-04-23 13:04:38

标签: javascript

我从服务中收到以下回复。我想获取URL(嵌套在内部)的值。我尝试做context.ExecutionContextHost.agrs[0].url,并尝试了几种其他组合,但似乎无济于事。

ExecutionContextHost {
  args:
   [ IncomingMessage {
       _readableState: [ReadableState],
       readable: true,
       domain: null,
       _events: {},
       _eventsCount: 0,
       _maxListeners: undefined,
       socket: [Socket],
       connection: [Socket],
       complete: false,
       headers: [Object],
       rawHeaders: [Array],
       trailers: {},
       rawTrailers: [],
       aborted: false,
       upgrade: false,
       url: '/current-content?id=MAIN&type=faqs',
       method: 'GET',
       statusCode: null,
       statusMessage: null,
       client: [Socket],
       _consuming: false,
       _dumped: false,
       next: [Function: next],
       baseUrl: '',
       originalUrl: '/current-content?id=MAIN&type=faqs',
       _parsedUrl: [Url],
       params: {},
       query: [Object],
       res: [ServerResponse],
       body: {},
       route: [Route] },
     ServerResponse {
       domain: null,
       _events: [Object],
       _eventsCount: 1,
       connection: [Socket],
       _header: null,
       _onPendingData: [Function: bound updateOutgoingData],
       _sent100: false,
       _expect_continue: false,
       req: [IncomingMessage],
       locals: {},
       [Symbol(isCorked)]: false,
       [Symbol(outHeadersKey)]: [Object] } ],
  constructorRef: [Function: CurrentContentController],
  handler: [Function: getCurrentContent] }

2 个答案:

答案 0 :(得分:3)

我不得不删除一些我没有引用的对象,以便此示例可以正常工作...但是在这里调用response.args[0].url似乎可以正常工作。

var response = {
  args: [ //IncomingMessage
  {
      readable: true,
      domain: null,
      _events: {},
      _eventsCount: 0,
      _maxListeners: undefined,
      complete: false,
      trailers: {},
      rawTrailers: [],
      aborted: false,
      upgrade: false,
      url: '/current-content?id=MAIN&type=faqs',
      method: 'GET',
      statusCode: null,
      statusMessage: null,
      _consuming: false,
      _dumped: false,
      baseUrl: '',
      originalUrl: '/current-content?id=MAIN&type=faqs',
      params: {},
      body: {},
    },
    //ServerResponse
    {
      domain: null,
      _eventsCount: 1,
      _header: null,
      _sent100: false,
      _expect_continue: false,
      locals: {}
    }
  ]
};

console.log(response.args[0].url)

答案 1 :(得分:0)

response.args[0].url 

可以工作