相关文章推荐
长情的刺猬  ·  expected bytes, str ...·  1 月前    · 
暗恋学妹的墨镜  ·  Caused by: ...·  1 年前    · 
烦恼的日记本  ·  (数据库篇) SQL查询~ ...·  1 年前    · 
我创建了一个Custom Runtime的HTTP函数,其中服务名为 CustomDemo 、函数名为 func-http ,并且设置了匿名的HTTP触发器,实现Custom Runtime的HTTP Server的路由代码示例如下:
@app.route('/test', methods = ['POST','GET'])
def test():
当我使用cURL工具或浏览器等方式访问HTTP函数的URL时,遇到 404 报错。
  • 使用cURL工具访问HTTP函数。
    curl  -v  https://164901546557****.cn-hangzhou.fc.aliyuncs.com/2016-08-15/proxy/CustomDemo/func-http/test
  • 使用浏览器访问HTTP函数。
    https://164901546557****.cn-hangzhou.fc.aliyuncs.com/2016-08-15/proxy/CustomDemo/func-http/test
    您可以选择以下任意方式解决该问题:
  • 使用 函数计算 为新建HTTP触发器分配的子域名重新访问。具体信息,请参见 步骤三:测试函数

    子域名格式如下:

    https://<subdomain>.<region_id>.fcapp.run/[action?queries] 

    本文的访问示例如下:

    https://funcname-svcname-khljsjksld.cn-shanghai.fcapp.run/action?hello=world
  • 在访问的命令中增加名为 x-fc-invocation-target 的Header。访问格式如下:
    curl -v -H "x-fc-invocation-target: 2016-08-15/proxy/$ServiceName/$functionName" https://<account_id>.<region_id>.fc.aliyuncs.com/$path
    本文的访问示例如下:
    curl -v -H "x-fc-invocation-target: 2016-08-15/proxy/CustomDemo/func-http" https://164901546557****.cn-hangzhou.fc.aliyuncs.com/test
  • 为您的函数绑定自定义域名,绑定成功后再执行以下命令重新访问即可。关于绑定域名的操作步骤,请参见 配置自定义域名 。 假设域名是 example.com ,访问格式如下:
    curl -v  https://example.com/$path
    本文的访问示例如下:
    curl -v  https://example.com/test
  • 修改您的函数代码,并且成功部署函数后,重新使用默认的URL访问即可。函数代码修改示例如下:
    @app.route('/2016-08-15/proxy/CustomDemo/func-http/test', methods = ['POST','GET'])
    def test():
    本文的访问示例如下:
    curl  -v  https://164901546557****.cn-hangzhou.fc.aliyuncs.com/2016-08-15/proxy/CustomDemo/func-http/test
  •