Skip to content

Commit eee950e

Browse files
authored
fixing the code (#3587)
1 parent ee31e46 commit eee950e

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

hub/dev-environment/rust/rss-reader-rust-for-windows.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ manager: jken
77
ms.topic: article
88
keywords: rust, windows 10, microsoft, learning rust, rust on windows for beginners, rust with vs code, rust for windows
99
ms.localizationpriority: medium
10-
ms.date: 12/09/2022
10+
ms.date: 05/22/2023
1111
---
1212

1313
# RSS reader tutorial (Rust for Windows with VS Code)
@@ -72,7 +72,7 @@ Now let's try out Rust for Windows by writing a simple console app that download
7272
...
7373

7474
fn main() -> Result<()> {
75-
let uri = Uri::CreateUri(h!("https://blog.rust-lang.org/feed.xml"))?;
75+
let uri = Uri::CreateUri(h!("https://blogs.windows.com/feed"))?;
7676

7777
Ok(())
7878
}
@@ -91,7 +91,7 @@ Now let's try out Rust for Windows by writing a simple console app that download
9191
...
9292

9393
fn main() -> windows::core::Result<()> {
94-
let uri = Uri::CreateUri(h!("https://blog.rust-lang.org/feed.xml"))?;
94+
let uri = Uri::CreateUri(h!("https://blogs.windows.com/feed"))?;
9595
let client = SyndicationClient::new()?;
9696

9797
Ok(())
@@ -107,7 +107,7 @@ Now let's try out Rust for Windows by writing a simple console app that download
107107
...
108108

109109
fn main() -> windows::core::Result<()> {
110-
let uri = Uri::CreateUri(h!("https://blog.rust-lang.org/feed.xml"))?;
110+
let uri = Uri::CreateUri(h!("https://blogs.windows.com/feed"))?;
111111
let client = SyndicationClient::new()?;
112112
let feed = client.RetrieveFeedAsync(&uri)?.get()?;
113113

@@ -117,15 +117,21 @@ Now let's try out Rust for Windows by writing a simple console app that download
117117

118118
Because [**RetrieveFeedAsync**](/uwp/api/windows.web.syndication.syndicationclient.retrievefeedasync) is an asynchronous API, we use the blocking **get** function to keep the example simple. Alternatively, we could use the `await` operator within an `async` function to cooperatively wait for the results. A more complex app with a graphical user interface will frequently use `async`.
119119

120-
9. Now we can iterate over the resulting items, and let's print out just the titles.
120+
9. Now we can iterate over the resulting items, and let's print out just the titles. You'll also see a few extra lines of code below to set a user-agent header, since some RSS feeds require that.
121121

122122
```rust
123123
// src\main.rs
124124
...
125125

126126
fn main() -> windows::core::Result<()> {
127-
let uri = Uri::CreateUri(h!("https://blog.rust-lang.org/feed.xml"))?;
127+
let uri = Uri::CreateUri(h!("https://blogs.windows.com/feed"))?;
128128
let client = SyndicationClient::new()?;
129+
130+
client.SetRequestHeader(
131+
h!("User-Agent"),
132+
h!("Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)"),
133+
)?;
134+
129135
let feed = client.RetrieveFeedAsync(&uri)?.get()?;
130136

131137
for item in feed.Items()? {

0 commit comments

Comments
 (0)