gpt4 book ai didi

azure - 从另一个 Azure 函数调用一个 Azure 函数时出现 403(禁止)

转载 作者:行者123 更新时间:2023-12-03 01:44:05 24 4
gpt4 key购买 nike

我需要调用一个azure函数; fn(b),来自另一个 Azure 函数; fn(a)。

fn(a) -> fn(b)

这两个功能都在同一个功能应用程序中。问题是每当我尝试调用 (b) 时,我都会收到 403-Forbidden“根级别的数据无效”。

是否可以从同一函数应用程序中的另一个azure函数调用azure函数?

函数1

public static class Function1
{
[FunctionName("Function1")]
public static async Task<HttpResponseMessage> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)]
HttpRequestMessage req, TraceWriter log)
{
log.Info("---- C# HTTP trigger function 1 processed a request.");

UploadToF2(log);
return null;
}

private static IRestResponse UploadToF2(TraceWriter log)
{
SomeObject payload = new SomeObject();
payload.One = "One";
payload.Two = 2;
payload.Three = false;
payload.Four = 4.4;

var Fn2Url = Convert.ToString(ConfigurationManager.AppSettings["F2Url"]);
log.Info("Hitting F2 at " + Fn2Url);
var method = Method.POST;
var client = new RestClient(Fn2Url);
var body = JsonConvert.SerializeObject(payload);

var request = new RestRequest(method);
request.RequestFormat = DataFormat.Json;
request.AddHeader("Content-Type", "application/json");

request.AddBody(payload); // uses JsonSerializer

IRestResponse response = client.Execute(request);
return response;
}
}

class SomeObject
{
public string One { get; set; }
public int Two { get; set; }
public bool Three { get; set; }
public double Four { get; set; }
}

函数2

public static class Function2
{
[FunctionName("Function2")]
public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)]HttpRequestMessage req, TraceWriter log)
{
log.Info("---- C# HTTP trigger function 2 processed a request.");
string payload = await req.Content.ReadAsStringAsync();
log.Info("payload == "+payload);

return null;
}
}

其他信息:

  1. F2Url 是来自配置的完全限定 URL。
  2. 我尝试在本地主机中运行这两个函数。有用。 IE。 fn(a) 可以在本地主机中调用 fn(b)。但是,当我将它们都托管在 Azure 中时,无法从 fn(a) 调用 fn(b)。
  3. 我也尝试过混合测试。 IE。我在本地保留了一项功能,在 Azure 中保留了另一项功能。它也是这样工作的。 IE。我将 fn(a) 保存在本地,将 fn(b) 保存在 Azure 中,fn(b) 是可调用的。
  4. 我尝试直接从 Postman 调用 fn(b),结果再次成功。
  5. authLevel 对于这两个函数都是匿名的
  6. 我对函数应用应用了 IP 限制(平台功能 > 网络 > IP 限制)。当我删除 IP 限制时,Function1 可以调用 Function2。但保留 IP 限制,不允许调用。

fn(a) 无法调用 fn(b) 的唯一条件是这两个函数都托管在 Azure 中。

最佳答案

403 (Forbidden) while calling one azure function from another

如果没有在IP限制中添加客户端IP,那么你在客户端测试它会得到403错误。如果不在IP限制中添加客户端IP,不仅从另一个调用azure函数,而且所有函数都会受到限制。

根据您的情况,您需要添加测试 client Ip在IP限制下,就可以了。

enter image description here

enter image description here

更新:

添加测试结果。

enter image description here

关于azure - 从另一个 Azure 函数调用一个 Azure 函数时出现 403(禁止),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49429969/

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