无法从cURL执行AWS API网关URL

问题描述 投票:0回答:1

我创建了一个简单的api网关,它将触发lambda函数并向调用者返回一些欢迎消息。

如果我从浏览器调用api url,它适用于http(内部重定向到https)和https调用。

如果我使用cURL调用,http调用不会重定向到https,我收到以下错误:

HTTP/1.1 301 Moved Permanently
Server: CloudFront
Date: Wed, 28 Feb 2018 11:27:48 GMT
Content-Type: text/html
Content-Length: 183
Connection: keep-alive
Location: https://f1234567.execute-api.ap-southeast-1.amazonaws.com/test
X-Cache: Redirect from cloudfront
Via: 1.1 werfdbdcc66044d560a313352d21.cloudfront.net (CloudFront)
X-Amz-Cf-Id: sfdgfgsdqr7WzN85pe0AD6565bEKZoT4x56gN24dfgdf

<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<center>CloudFront</center>
</body>
</html>

下一步,我想从我的硬件设备中调用此api url。

amazon-web-services aws-api-gateway
1个回答
2
投票

这不是错误。您所看到的是您想要的确切行为--301重定向。但是curl不遵循重定向(例如,与浏览器不同),除非明确告知这样做。

-L开关添加到curl调用将启用重定向。

您还可以启用详细标记-v,并观察它在重定向到https之前会达到301。

© www.soinside.com 2019 - 2024. All rights reserved.