【问题标题】:Save-AzureWebSiteLog Invoke-WebRequest errorSave-AzureWebSiteLog Invoke-WebRequest 错误
【发布时间】:2016-01-06 23:54:07
【问题描述】:

我真的很接近完成我的工作,但它开始导致这个错误。

当我执行此操作时

Save-AzureWebSiteLog -Name $WebSiteName -Output "C:\logs\error.zip"

Save-AzureWebSiteLog :传入的最大邮件大小配额 已超出消息 (65536)。要增加配额,请使用 相应绑定元素上的 MaxReceivedMessageSize 属性。

所以,我搜索了解决方案,似乎很多人都有完全相同的问题。

https://azure.microsoft.com/en-us/blog/windows-azure-websites-online-tools-you-should-know-about/

感谢@Parth Sehgal,我尝试使用powershell 解决问题

$username = "maiemai"
$password = "Password"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))
$apiUrl = "https://wngphase2it.scm.azurewebsites.net/api/zip/LogFiles/"
$response = Invoke-WebRequest -Uri $apiUrl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method GET 
try
{
$filename = [System.IO.Path]::GetFileName($response.BaseResponse.ResponseUri.OriginalString)
$filepath = [System.IO.Path]::Combine("c:\asdf\", "http1.zip")
$filestream = [System.IO.File]::Create($filepath)
$response.RawContentStream.WriteTo($filestream)
}
finally
{
$filestream.Close()
}

但我遇到了这个错误

Invoke-WebRequest:服务器错误 401 - 未经授权:由于凭据无效,访问被拒绝。 您无权使用您提供的凭据查看此目录或页面。 在行:5 字符:13 + $response = Invoke-WebRequest -Uri $apiUrl -Headers @{Authorization=("Basic {0}" ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], 网络异常 + FullyQualifiedErrorId:WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand 您不能在空值表达式上调用方法。 在行:11 字符:1 + $response.RawContentStream.WriteTo($filestream) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull

用户名和密码肯定是正确的,但还是会导致这个错误。

我应该如何更改这一行?

$response = Invoke-WebRequest -Uri $apiUrl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method GET 

【问题讨论】:

  • 您使用的是 Kudu 的部署凭据,而不是您的 Azure 门户凭据,对吧?

标签: azure azure-powershell kudu


【解决方案1】:

首先,在这种情况下,您的用户名不正确。

为了使用 Azure Kudu REST API 来检索您的 Azure Web 应用的压缩日志文件,您需要在 发布配置文件 中使用您的 Web 应用的 MSDeploy 凭据强> 文件。

Azure Web 应用的 MSDeploy 用户名的正确形式应该是 ${yoursitename}

您可以从新的 Azure 门户或通过 Azure PowerShell 命令获取 Web 应用的发布配置文件:Get-AzureRMWebAppPublishingProfile

我还在您的 PowerShell 脚本中解决了这个问题,我使用自己的网络应用程序进行了测试。

$username = "`$wngphase2it"
$password = "yourMSDeployUserPwd"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))
$apiUrl = "https://wngphase2it.scm.azurewebsites.net/api/zip/LogFiles/"
$response = Invoke-WebRequest -Uri $apiUrl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method GET 
try
{
$filename = [System.IO.Path]::GetFileName($response.BaseResponse.ResponseUri.OriginalString)
$filepath = [System.IO.Path]::Combine("c:\asdf\", "http1.zip")
$filestream = [System.IO.File]::Create($filepath)
$response.RawContentStream.WriteTo($filestream)
}
finally
{
$filestream.Close()
}

参考:Sample of using Kudu REST API with PowerShell

让我知道它是否有助于解决您的问题。

【讨论】:

    猜你喜欢
    • 2012-07-26
    • 1970-01-01
    • 1970-01-01
    • 2021-03-30
    • 1970-01-01
    • 1970-01-01
    • 2020-12-30
    • 2016-07-15
    相关资源
    最近更新 更多