本文介绍了无法访问 Azure Functions 的管理员 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 powershell 并尝试使用 api 访问 Azure 功能管理.我正在尝试获取在 $appName

I am using powershell and trying to access Azure functions Administration using api.I am trying to get list of all functions created under $appName

当然,我在调用之前用实际的 Azure 函数名称更改 $appName

Certainly i am changing $appName with actual Azure Function name before call

在此调用之前,我还获得了有效的 $authToken.

I also got valid $authToken before this call.

以下网址:

$Functions = Invoke-RestMethod -Method GET -Headers @{Authorization = ("Bearer {0}" -f $authToken)} -Uri "https://$appName.azurewebsites.net/admin/functions"

我的PowerShell执行中的错误是:

and the error in my powershell execution is :

调用-RestMethod:

Invoke-RestMethod :

The underlying connection was closed: An unexpected error occurred on a send.
At KeyFA.ps1:36 char:18
+ ... Functions = Invoke-RestMethod -Method GET -Headers @{Authorization =  ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

我尝试将其设为 POST 而不是 GET 但同样的错误.

I tried make it POST instead of GET but same error.

我尝试在浏览器中访问此网址,但浏览器中的错误是:

I tried access this url in broswer and the error in my broswer is :

http 401 表示未经授权.

http 401 means unauthorized.

然后我也尝试从 postman 访问此 URL,但正确设置了 Bearer 身份验证,但出现以下错误:

Then i also tried access this URL from postman with Bearer auth correctly set but get below errors:

Could not get any response
There was an error connecting to
https://appname_comes_here.azurewebsites.net/admin/functions/

我做错了什么?

无法修复此错误.Azure 功能站点现在是否已停止使用该 url?

Not able to fix this error. Is the url discontinued by Azure function site now?

推荐答案

由于您只是发布了部分PowerShell代码,并且错误信息似乎是网络问题,我不知道您遇到的真正问题是什么以及如何修复它.

Due to you just post the partial PowerShell code and the error information seems to be a network issue, I don't know what real issue you got is and how to fix it.

所以我只是在这里发布我的工作 PowerShell 脚本,您可以参考我的代码来解决您的问题.

So I just post my work PowerShell script at here, you can refer to my code to fix your issue.

$appName = "<your app name>"
$userName='<your app credential user name>'
$userPWD='<your app credential user password>'

$apiBaseUrl = "https://$($appName).scm.azurewebsites.net/api"
$appBaseUrl = "https://$($appName).azurewebsites.net"

$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $userName,$userPWD)))

$jwt = Invoke-RestMethod -Uri "$apiBaseUrl/functions/admin/token" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method GET

$Functions = Invoke-RestMethod -Method GET -Headers @{Authorization = ("Bearer {0}" -f $jwt)} -Uri "$appBaseUrl/admin/functions"

注意:您可以按照下图获取$userName$userPWD的值.

Note: you can follow the figures below to get the $userName and $userPWD values.

图 1. 在 Azure 门户上,打开 Function App 的 Platform features 选项卡,然后单击 Deployment Center 链接

Fig 1. On Azure portal, open the Platform features tab of your Function App and click the Deployment Center link

图2.选择SOURCE CONTROL第一步中的FTP选项,点击Dashboard按钮复制Username 和 Password,但只使用 Username 中带有 $ 前缀的部分作为 $userName在我的脚本中

Fig 2. Select the FTP option in the first step of SOURCE CONTROL and click the Dashboard button to copy the values of Username and Password, but just use the part of Username with $ prefix as $userName in my script

这篇关于无法访问 Azure Functions 的管理员 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 19:12
查看更多