403(禁止)从一个azure函数调用另一个azure函数时
我需要调用azure函数;fn(b),来自另一个azure函数;fn(a) fn(a)->fn(b) 这两个函数都在同一个函数应用程序中。问题是每当我尝试调用(b)时,我都会得到403个“根级别的数据无效” 是否可以在同一个函数应用程序中从另一个azure函数调用azure函数 功能1403(禁止)从一个azure函数调用另一个azure函数时,azure,azure-functions,http-status-code-403,Azure,Azure Functions,Http Status Code 403,我需要调用azure函数;fn(b),来自另一个azure函数;fn(a) fn(a)->fn(b) 这两个函数都在同一个函数应用程序中。问题是每当我尝试调用(b)时,我都会得到403个“根级别的数据无效” 是否可以在同一个函数应用程序中从另一个azure函数调用azure函数 功能1 public static class Function1 { [FunctionName("Function1")] public static async Task&l
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; }
}
公共静态类函数1
{
[功能名称(“功能1”)]
公共静态异步任务运行(
[HttpTrigger(AuthorizationLevel.Anonymous,“获取”、“发布”,路由=null)]
HttpRequestMessage请求,TraceWriter日志)
{
log.Info(--C#HTTP触发器函数1处理了一个请求);
上传TOF2(日志);
返回null;
}
专用静态iRestreponse上载到F2(TraceWriter日志)
{
SomeObject有效负载=新的SomeObject();
有效载荷.One=“One”;
有效载荷。2=2;
有效载荷。3=错误;
有效载荷4=4.4;
var Fn2Url=Convert.ToString(ConfigurationManager.AppSettings[“F2Url”]);
log.Info(“在“+Fn2Url”处点击F2);
var方法=method.POST;
var client=新的RestClient(Fn2Url);
var body=JsonConvert.SerializeObject(有效负载);
var请求=新的重新请求(方法);
request.RequestFormat=DataFormat.Json;
AddHeader(“内容类型”、“应用程序/json”);
request.AddBody(有效负载);//使用JsonSerializer
IRestResponse response=client.Execute(请求);
返回响应;
}
}
类对象
{
公共字符串One{get;set;}
公共整数二{get;set;}
公共布尔三{get;set;}
公共双四{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;
}
}
公共静态类函数2
{
[功能名称(“功能2”)]
公共静态异步任务运行([HttpTrigger(AuthorizationLevel.Anonymous,“get”,“post”,Route=null)]HttpRequestMessage请求,TraceWriter日志)
{
log.Info(--C#HTTP触发器函数2处理了一个请求);
字符串有效负载=wait req.Content.ReadAsStringAsync();
log.Info(“有效载荷=”+有效载荷);
返回null;
}
}
其他信息:
authLevel
对这两个函数都是匿名的fn(a)无法调用fn(b)的唯一条件是这两个函数都托管在Azure中。在使用以下功能时,通过GET-to Function1在本地工作:
var Fn2Url = "http://localhost:7071/api/Function2";
您在配置中使用的值是什么?在使用以下选项时,通过“获取”功能1在本地工作:
var Fn2Url = "http://localhost:7071/api/Function2";
您在配置中使用了什么值
GET https://{func-app-name}.azurewebsites.net/api/function2
authLevel
在function.json
中不是匿名的,则将API键作为?code=
-
https://{func-app-name}.azurewebsites.net/api/function2?code={API-key}
或者作为标题-
GET https://{func-app-name}.azurewebsites.net/api/function2
x-functions-key: {API-key}
func host start
),将忽略authLevel
的值。看看你的装饰师,AuthorizationLevel.Anonymous
,很可能不是这样
更多关于
最重要的是,如果在函数2中返回null
,200ok
,202 Accepted
,204 No Content
,所有有效的选择都取决于接下来应该发生什么(异步/同步处理)
GET https://{func-app-name}.azurewebsites.net/api/function2
authLevel
在function.json
中不是匿名的,则将API键作为?code=
-
https://{func-app-name}.azurewebsites.net/api/function2?code={API-key}
或者作为标题-
GET https://{func-app-name}.azurewebsites.net/api/function2
x-functions-key: {API-key}
func host start
),将忽略authLevel
的值。看看你的装饰师,AuthorizationLevel.Anonymous
,很可能不是这样
更多关于
最重要的是,如果在函数2中返回null
,200ok
,202 Accepted
,204 No Content
,所有有效的选择都取决于接下来应该发生什么(异步/同步处理)
403(禁止)从一个azure函数调用另一个azure函数时
如果不将客户端Ip添加到Ip限制中,则在客户端中测试它将得到403错误。如果不在IP限制中添加客户端IP,则不仅从另一个客户端调用azure函数,而且所有函数都会受到限制
在您的情况下,您需要在IP限制中添加您的测试,然后它就可以工作了
更新:
添加测试结果
403(禁止)而calli