在运行Powershell命令时出现错误

时间:2020-01-03 14:01:18

标签: excel xml powershell

我遇到以下错误:

exception calling "UploadString" with "2" argument(s): "The remote server returned an error: (500) 
Internal Server Error." At C:\Cinegy_Type\Helpers-Type.ps1:146 char:5 + $web.UploadString($url, 
$xmlDoc.OuterXml) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], 
MethodInvocationException + FullyQualifiedErrorId : WebException

方法是这样的:

function Type-UpdateVariable([string]$name, [string]$value, [string]$type = "Text", [string]$server="localhost", [int]$instance=0)
{
    #make a Type PostRequest XML document using .Net XML document object
    $xmlDoc = New-Object System.Xml.XmlDocument;

    #add root element for request - which is a 'PostRequest' element
    $xmlRootElem =  $xmlDoc.AppendChild($xmlDoc.CreateElement('PostRequest'));

    #create SetValue element and define variable Name, Type and Value
    $xmlSetValueElem = $xmlRootElem.AppendChild($xmlDoc.CreateElement('SetValue'));
    $xmlSetValueElem.SetAttribute("Name", $name);
    $xmlSetValueElem.SetAttribute("Type",$type);
    $xmlSetValueElem.SetAttribute("Value", $value);

    #create a .Net webclient which will be used to perform the HTTP POST
    $web = new-object net.webclient

    #Air requires that the data is in XML format and declared properly - so add the HTTP Header to state this
    $web.Headers.add("Content-Type", "text/xml; charset=utf-8")

    #perform the actual HTTP post to the IP and port (which is 5521 + instance number) of the XML data
    $url = "http://" + $server + ":" + (5521 + $instance) + "/postbox"
    $web.UploadString($url, $xmlDoc.OuterXml)
}

第146行是: $web.UploadString($url, $xmlDoc.OuterXml)

我不知道这是昨天工作的。

完整的代码可以在这里找到:(这里没有使用行号作为参考,因为它有3个脚本。)

https://pastebin.com/RtisgmiB

1 个答案:

答案 0 :(得分:0)

您要发布到的Web服务器出现问题; see meaning of a HTTP status code 500。除非传递给函数的数据有问题,否则代码看起来不错。该Powershell错误消息中没有丢失任何内容,它将为您提供有关该问题的线索。

  1. 检查Web服务器上的错误日志(最佳选项)
  2. 将参数输出到控制台,目的是通过Postman,cURL等手动提交请求。

祝你好运!