保存-AzureWebSiteLog 调用-WebRequest 错误

Save-AzureWebSiteLog Invoke-WebRequest error

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

当我执行这个

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

Save-AzureWebSiteLog : The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.

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

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 : Server Error 401 - Unauthorized: Access is denied due to invalid credentials. You do not have permission to view this directory or page using the credentials that you supplied. At line:5 char:13 + $response = Invoke-WebRequest -Uri $apiUrl -Headers @{Authorization=("Basic {0}" ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand You cannot call a method on a null-valued expression. At line:11 char:1 + $response.RawContentStream.WriteTo($filestream) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull

用户名和密码肯定是正确的,但还是出现这个错误

我应该如何更改此行?

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

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

为了使用 Azure Kudu REST API 检索 Azure 网络应用程序的压缩日志文件,您需要使用网络应用程序的 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

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