如何在Azure Functions中设置HTTP输出 [英] How to set up HTTP outputs in Azure Functions

查看:100
本文介绍了如何在Azure Functions中设置HTTP输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的Azure函数,为此我设置了DocumentDB输出:

然后,

我在函数中添加了outputDocument参数,并在代码中为其分配了一个值(通过这种方式,我感到惊讶的是,当我设置输出时,运行时不会自动修改函数签名):

using System;

public static void Run(string input, out object outputDocument, TraceWriter log)
{
    log.Info($"C# manually triggered function called with input: {input}");

    outputDocument = new {
        text = $"I'm running in a C# function! {input}"
    };
}

当我运行该函数时,Azure Functions运行时会执行绑定魔术,并创建DocumentDB文档.

然后我设置一个HTTP输出:

并定义了res输出参数.

但是现在呢?分配给res的过程是什么?我当然必须定义目标,请求类型,参数等.

解决方案

Howiecamp,

HTTP输出绑定与HTTP触发器一起用作HTTP请求的响应处理程序.

当前,没有可以通过HTTP为您发送输出有效负载的输出绑定,因此您需要根据功能代码发出该HTTP请求(例如,使用HttpClient并发出请求).您可以在此处的模板之一中查看示例:

When I run the function the Azure Functions runtime does it's binding magic and the DocumentDB document gets created.

I then set up an HTTP output:

and defined the res output parameter.

But now what? What's the process of assigning to res? I've of course got to define the destination, request type, parms, etc.

解决方案

Howiecamp,

The HTTP output binding works in conjunction with the HTTP Trigger to act as the response handler for an HTTP request.

Currently, there isn't an output binding that would send the output payload over HTTP for you, so you'd need to make that HTTP request from your function code (e.g. using the HttpClient and issuing the request). You can see an example in one of our templates here: https://github.com/Azure/azure-webjobs-sdk-templates/blob/10650dbf9c4bad75b0c89b9c355edc53fe913cde/Templates/GitHubCommenter-CSharp/run.csx#L40-L49

I hope this helps!

这篇关于如何在Azure Functions中设置HTTP输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆