Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.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
Azure functions 如何在Azure函数中获取对HTTPResponse对象的引用?_Azure Functions - Fatal编程技术网

Azure functions 如何在Azure函数中获取对HTTPResponse对象的引用?

Azure functions 如何在Azure函数中获取对HTTPResponse对象的引用?,azure-functions,Azure Functions,我有一个Azure v2(和v3预览)函数(HTTP触发器),其签名如下: public static async Task<IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger log) 公共静态异步任务运行( [HttpTrigger(Authori

我有一个Azure v2(和v3预览)函数(HTTP触发器),其签名如下:

public static async Task<IActionResult> Run(
        [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", 
        Route = null)] HttpRequest req,
        ILogger log)
公共静态异步任务运行(
[HttpTrigger(AuthorizationLevel.Anonymous,“获取”、“发布”,
路由=空)]HttpRequest请求,
ILogger日志)
我已经检查了文档并尽可能地进行了尝试,但是我找不到任何关于如何像在ASP.NET中那样获得对HTTPResponse对象的引用的引用


我正在尝试设置自定义标头和自定义cookie。HTTPRequest对象似乎无法访问任何与响应相关的内容。

如果要设置自定义标题,请参阅下面的代码:

public static class Function1
{
    [FunctionName("Function1")]
    public static HttpResponseMessage Run(
        [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req,
        ILogger log)
    {
        log.LogInformation("C# HTTP trigger function processed a request.");

        string testheader = req.Headers.GetValues("testheader").FirstOrDefault();
        string executionTime = DateTime.UtcNow.ToString();

        var httpresponse = req.CreateResponse(HttpStatusCode.OK, new
        {
            Testheader = testheader,
            ExecutionTime = executionTime
        }, "application/json");
        httpresponse.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html");
        httpresponse.Headers.Add("Warning", "custom header");
        return httpresponse;
     
    }
}
此代码使用
299-“不推荐的API”
值添加自定义标题
警告
,并更改
内容类型
标题


希望这能帮助您,如果您还有其他问题,请随时告诉我。

使用以下示例:

req.HttpContext.Response.Headers.Add("abcd", "12345");
req.HttpContext.Response.Cookies.Append("abcd", "12345");

req.HttpContext.Response.Headers.Add(“abcd”,“12345”);req.HttpContext.Response.Cookies.Append(“abcd”,“12345”);啊。这么简单。没有想到回到上下文,然后回到回应中。谢谢接受答案,如果它是一个!