【问题标题】:Unable to access admin URL of Azure Functions无法访问 Azure Functions 的管理员 URL
【发布时间】:2019-07-17 11:46:49
【问题描述】:

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

下创建的所有函数的列表

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

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

以下网址:

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

我的PowerShell执行中的错误是:

调用-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 但同样的错误。

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

http 401 表示未经授权。

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

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

我做错了什么?

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

【问题讨论】:

标签: azure powershell azure-functions azure-app-service-envrmnt


【解决方案1】:

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

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

$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 的值。

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

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

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-31
  • 1970-01-01
  • 2021-08-09
  • 2022-11-10
  • 2017-06-23
  • 1970-01-01
相关资源
最近更新 更多