保存azurewebsitelog调用webrequest错误

nhaq1z21  于 2021-06-20  发布在  Kudu
关注(0)|答案(1)|浏览(381)

我真的很快就要完成我的工作,但它开始导致这个错误。
当我执行这个的时候

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-未授权:由于凭据无效,访问被拒绝。您没有使用您提供的凭据查看此目录或页面的权限。在line:5 char:13+$response=invoke webrequest-uri$apiurl-headers@{授权=(“基本{0}”…+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+类别信息:invalidoperation:(system.net.httpw)ebrequest:httpwebrequest)[调用webrequest],webexception+fullyqualifiederrorid:webcmdletwebresponseexception,microsoft.powershell.commands.invokewebrequestcommand不能对空值表达式调用方法。在line:11 char:1+$response.rawcontentstream.writeto($filestream)+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+categoryinfo:invalidoperation:(:)[],runtimeexception+fullyqualifiederrorid:InvokeMethodUnll
用户名和密码是绝对正确的,但它仍然会导致此错误。
我该怎么换这条线?

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

mzillmmw1#

首先,你的用户名在这种情况下是不正确的。
为了使用azure kudu rest api检索azure web应用的压缩日志文件,您需要在发布配置文件中使用web应用的msdeploy凭据。
azure web应用的msdeploy用户名的正确形式应该是${yoursitename}。
您可以从新的azure门户或通过azure powershell命令获取web应用的发布配置文件: Get-AzureRMWebAppPublishingProfile 我还修复了powershell脚本中的问题,我用自己的web应用程序测试了该脚本。

$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()
}

参考:将kudurestapi与powershell结合使用的示例
让我知道这是否有助于解决您的问题。

相关问题