Powershell 中的 Invoke-RestMethod 只返回内部入口元素而不返回 feed

Invoke-RestMethod in Powershell only returning inner entry elements and not feed

我在具有以下结构的提要上调用 Powershell 的 Invoke-RestMethod

<feed>
    <id>feed id</id>
    <author><name>John Smith</name></author>
    <title>Feed title</title>
    <updated>2017-03-17T12:57:28.898Z</updated>
    <link href="url A" rel="value A"/>
    <link href="url B" rel="value B"/>
    ... other elements ...
    <entry>
        <id>entry id</id>
        <author><name>John Smith</name></author>
        <title>Entry title</title>
        <updated>2017-03-17T12:57:28.898Z</updated>
        <link href="url C" rel="value C"/>
        <link href="url D" rel="value D"/>
        ... other elements ...
    </entry>
</feed>

我正在使用以下功能

$xml = Invoke-RestMethod -Method Get -Uri $Url -ContentType "application/atom+xml" -Credential $credentials

我得到一个成功的响应,但它只包含 <entry> 元素而不包含 <feed> 元素,我需要 "url A" 和 "url B" 的值因此不会返回链接。

通常情况下,我会说出我在这一点上尝试过的内容,但由于我在 Internet 上找不到任何内容,所以我只尝试过这些内容。

  1. 将请求内容类型更改为 "text/xml" - 结果没有变化。
  2. 正在调用 $xml.ParentNode$xml.OwnerDocument 试图获取 <feed> 元素,但它不可用。

如何获得 <feed> 关卡元素?

我的 Powershell 版本是 5.1.14393.953

谢谢

Invoke-RestMethod 仅 returns rss 或 atom-feed 中的条目,如 MSDN:

所述

Windows PowerShell formats the response based to the data type. For an RSS or ATOM feed, Windows PowerShell returns the Item or Entry XML nodes. For JavaScript Object Notation (JSON) or XML, Windows PowerShell converts (or deserializes) the content into objects.

您可以使用 Invoke-WebRequest 阅读原文 xml 并访问提要元素。例如

$xml = [xml](Invoke-WebRequest -Uri $url -Credential $credentials)

示例输出:

PS> $xml.feed   

xmlns   : http://www.w3.org/2005/Atom
title   : VG ATOM Feed
link    : {link, link}
id      : http://www.vg.no/rss/feed/forsiden/?format=atom
updated : 2017-03-19T18:36:56+01:00
entry   : {entry, entry, entry, entry...}