Save-AzureWebSiteLog Invoke-WebRequest error



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

当我执行这个时

Save-AzureWebSiteLog -Name $WebSiteName -Output "C:logserror.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()
}

但是我被这个错误卡住了

调用WebRequest:服务器错误401-未经授权:由于凭据无效,访问被拒绝。您没有使用您提供的凭据查看此目录或页面的权限。第5行字符:13+$response=调用WebRequest-Uri$apiUrl-Headers@{Authorization=("基本{0}"。。。+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+CategoryInfo:InvalidOperation:(System.Net.HttpWebRequest:HttpWebRequest)[IInvoke-WebRequest],WebException+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 

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

为了使用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()
}

参考资料:使用Kudu REST API与PowerShell 的示例

让我知道这是否有助于解决你的问题。

相关内容

最新更新