Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Https 获取请求到API请求,给出状态代码502。我如何解决这个问题?_Https_Nestjs - Fatal编程技术网

Https 获取请求到API请求,给出状态代码502。我如何解决这个问题?

Https 获取请求到API请求,给出状态代码502。我如何解决这个问题?,https,nestjs,Https,Nestjs,我正在用nestjs框架构建一个应用程序。我已经创建了控制器和服务来从Http端点获取数据。我得到的不是json数据,而是 错误:请求失败,状态代码为502 在createError(node_modules/axios/lib/core/createError.js:16:15) 结算时(node_modules/axios/lib/core/solite.js:17:12) 在IncomingMessage.handleStreamEnd(node_modules/axios/lib/ada

我正在用nestjs框架构建一个应用程序。我已经创建了控制器和服务来从Http端点获取数据。我得到的不是json数据,而是

错误:请求失败,状态代码为502
在createError(node_modules/axios/lib/core/createError.js:16:15)
结算时(node_modules/axios/lib/core/solite.js:17:12)
在IncomingMessage.handleStreamEnd(node_modules/axios/lib/adapters/http.js:237:11)
在IncomingMessage.emit(events.js:203:15)
在endReadableNT(_stream_readable.js:1145:12)
在进程中。在输出中勾选回调(internal/process/next_tick.js:63:19)
端点在Google Chrome上运行良好。我已将我的应用程序与Swagger UI集成。为了从端点获取数据,我应该在代码中做哪些更改

这是我的服务

import { Injectable, HttpService } from '@nestjs/common';
import { map } from 'rxjs/operators';

@Injectable()
export class MessageService {
  constructor(private readonly httpService: HttpService) {}

  configEndPoint: string = 'https://jsonplaceholder.typicode.com/todos/1';

  getData(source: string, productCode: string, vehicleType: string) {
    return this.httpService
      .get(this.configEndPoint)
      .pipe(map(response => response.data.json()));
  }
}

这是我的控制器

import { Controller, Post, Body, Get } from '@nestjs/common';
import {
  ApiImplicitHeader,
  ApiOperation,
  ApiResponse,
  ApiUseTags,
} from '@nestjs/swagger';
import { ProductEvent } from '../dto/product-event';
import { MessageService } from '../service/message/message-service';

@Controller('/service/api/message')
export class MessageController {
  source: string;
  productCode: string;
  vehicleType: string;
  constructor(private messageService: MessageService) {}

  @Post()
  @ApiUseTags('processor-dispatcher')
  @ApiOperation({ title: 'Generate product message for the SNS topics' })
  async generateMessage(@Body() productEvent: ProductEvent) {


    return JSON.stringify(
      this.messageService.getData(
        this.source,
        this.productCode,
        this.vehicleType,
      ),
    );
  }
}


这是从localhost发生的还是当您的应用程序托管在某个地方时发生的?你是在防火墙里还是在类似的地方?你能发布你得到的全部错误吗?是的,这在本地主机上发生。我正在使用Swagger UI获取请求。我已经更新了错误消息,当您使用cURL或Postman?时会发生什么?在禁用ssl证书验证后,Postman上的响应将按预期进行。我使用的vscode editorA 502是一个错误的网关响应,因此SSL证书似乎有问题,或者有某种防火墙阻止了您的应用程序(尽管有疑问,因为Postman正在工作)