我在SharePoint 2013上有一项服务,负责管理自定义菜单。 我试图像PowerShell一样使用PowerShell中的这项服务:
$MenuItem = New-Object -TypeName PSObject
$MenuItem | Add-Member -MemberType NoteProperty -Name LinkEN -Value $pageLink
$MenuItem | Add-Member -MemberType NoteProperty -Name LinkFR -Value $pageLink
$MenuItem | Add-Member -MemberType NoteProperty -Name TitleEN -Value $pageParam.ListTitle;
$MenuItem | Add-Member -MemberType NoteProperty -Name TitleFR -Value $pageParam.ListTitle;
$body = @{ _menuItem = $MenuItem; _parent = $null } | ConvertTo-Json
$url = $url + "/_vti_bin/MenuService.svc/AddMenuItem"
$result = Invoke-RestMethod -Uri $url -Method Post -UseDefaultCredentials -ContentType "application/json; charset=utf-8" -Body $body
当我尝试通过参数(例如:è
)发送带重音的字母(例如$pageParam.ListTitle = "ètè"
)时,它工作正常。
在这种情况下,我收到以下错误:
Invoke-RestMethod : Request Error The server encountered an error processing the request. See server logs for more details. At FixDocumentPages.ps1:145 char:19 + $result = Invoke-RestMethod -Uri $url -Method Post -UseDefaultCredential ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
我在服务器代码中有断点,但它永远不会那么远。
以下是此事件的SharePoint日志:
输入受监视的范围(请求(POST:http:// wssppoc:5000 / _vti_bin / MenuService.svc / AddMenuItem))。父无名称=请求(POST:http:// wssppoc:5000 / _vti_bin / MenuService.svc / AddMenuItem)4af4519d-0879-c02e-e1ad-bb2bcbb09abb非OAuth请求。 IsAuthenticated = False,UserIdentityName =,ClaimsCount = 0 4af4519d-0879-c02e-e1ad-bb2bcbb09abb Micro Trace标签:0 nasq,1 agb9s 4af4519d-0879-c02e-e1ad-bb2bcbb09abb
离开受监视的范围(请求(POST:http:// wssppoc:5000 / _vti_bin / MenuService.svc / AddMenuItem))。执行时间= 1,7839 4af4519d-0879-c02e-e1ad-bb2bcbb09abb
输入受监视的范围(请求(POST:http:// wssppoc:5000 / _vti_bin / MenuService.svc / AddMenuItem))。父无名称=请求(POST:http:// wssppoc:5000 / _vti_bin / MenuService.svc / AddMenuItem)4af4519d-087a-c02e-e1ad-b0990e08ad35微量跟踪标签:0 nasq 4af4519d-087a-c02e-e1ad-b0990e08ad35
离开受监视的范围(请求(POST:http:// wssppoc:5000 / _vti_bin / MenuService.svc / AddMenuItem))。执行时间= 0,6495 4af4519d-087a-c02e-e1ad-b0990e08ad35
输入受监视的范围(请求(POST:http:// wssppoc:5000 / _vti_bin / MenuService.svc / AddMenuItem))。父无名称=请求(POST:http:// wssppoc:5000 / _vti_bin / MenuService.svc / AddMenuItem)4af4519d-087a-c02e-e1ad-bb3e80204d39非OAuth请求。 IsAuthenticated = True,UserIdentityName = 0#.w | test \ administrator,ClaimsCount = 29 4af4519d-087a-c02e-e1ad-bb3e80204d39 Micro Trace标签:0 nasq,1 agb9s 4af4519d-087a-c02e-e1ad-bb3e80204d39
离开受监视的范围(请求(POST:http:// wssppoc:5000 / _vti_bin / MenuService.svc / AddMenuItem))。执行时间= 3,9189 4af4519d-087a-c02e-e1ad-bb3e80204d39 ContentIntegrationEngine:执行已启动,流程标识符为4659ab80-0016-499b-a3ff-c1961ca797bd。
有没有人知道可能出现什么问题?
答案 0 :(得分:0)
Sam的回答正在导致正确的解决方案。正在使用:
[System.Text.Encoding] :: UTF8.GetBytes()
工作代码是:
$MenuItem = New-Object -TypeName PSObject
$MenuItem | Add-Member -MemberType NoteProperty -Name LinkEN -Value $pageLink
$MenuItem | Add-Member -MemberType NoteProperty -Name LinkFR -Value $pageLink
$MenuItem | Add-Member -MemberType NoteProperty -Name TitleEN -Value $pageParam.ListTitle;
$MenuItem | Add-Member -MemberType NoteProperty -Name TitleFR -Value $pageParam.ListTitle;
$body = @{ _menuItem = $MenuItem; _parent = $null } | ConvertTo-Json
$url = $url + "/_vti_bin/MenuService.svc/AddMenuItem"
$body = [System.Text.Encoding]::UTF8.GetBytes($body);
$result = Invoke-RestMethod -Uri $url -Method Post -UseDefaultCredentials -ContentType "application/json; charset=utf-8" -Body $body