gpt4 book ai didi

c# - Azure Function Post C# 不以大体执行

转载 作者:行者123 更新时间:2023-12-05 08:04:03 26 4
gpt4 key购买 nike

我目前正在实现一个 Azure Function App,它公开了一些函数(主要是 get)。

以下代码似乎有问题:

using System;
using System.Collections.Specialized;
using System.Net;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;
using System.Net.Http;
using InternalVacanciesAzureFunction.Model;
using Microsoft.Extensions.Options;
using System.Text.Json;
using System.Collections.Generic;

namespace IVAFunction
{
public class PostFunction
{
private readonly HttpClient _httpClient;

public PostFunction(IHttpClientFactory httpClientFactory)
{
_httpClient = httpClientFactory.CreateClient();
}

[Function("postFunction")]
public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "post", "put")] HttpRequestData req,
FunctionContext executionContext)
{
ILogger logger = executionContext.GetLogger("PostFunction");
logger.LogError("Code hit: PostFunction.cs");

HttpResponseData response = req.CreateResponse();

string body = new System.IO.StreamReader(req.Body).ReadToEnd();

JsonResponse data = Nfunction.postFunction(_httpClient, "/PostFunction", body, logger, requestPrincipalName);
if (data.responseType.Equals(ResponseType.OK))
{
response.StatusCode = HttpStatusCode.OK;
}
else
{
response.StatusCode = HttpStatusCode.InternalServerError;
}

response.Headers.Add("Content-Type", "application/json; charset=utf-8");
response.WriteString(data.json);

return response;
}
}
}

发布到此函数的数据是一个 JSON,其中两个字段中包含 BASE64 编码的字符串。这两个字段的最大大小均为 1.5MB。每次我发布一些小东西,例如2 x 400B,一切顺利。但是当我发送类似 2 x 900kB 的内容时,日志记录显示如下:

2021-12-07T07:42:28.455 [Debug] Request successfully matched the route with name 'postFunction' and template 'api/postFunction'

2021-12-07T07:42:29.129 [Information] Executing 'Functions.postFunction' (Reason='This function was programmatically called via the host APIs.', Id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx)

“代码命中”记录器代码永远不会被命中,一段时间后函数就会超时。

有人知道发生了什么事吗?我可以在本地开发环境以及实际的 Azure 上重现该问题。

最佳答案

那里缺少很多指令或程序集引用除了最后一个 } 是不必要的。

关于c# - Azure Function Post C# 不以大体执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70257853/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com