Getting feed items from Google reader belonging to a subscription whose URL contains a question mark (query string)?

StackOverflow https://stackoverflow.com/questions/14712751

  •  06-03-2022
  •  | 
  •  

سؤال

I am trying to get feeds belonging to a particular subscription in Google reader using the usual GET request to https://www.google.com/reader/api/0/stream/contents/feed/{FEED URL}?ot=1253052000&r=n&xt=user/-/state/com.google/read&n=20&ck=1255646178892&client=myApplication.

Everything seems to be fine except when the URL contains a query string such as http://www.aljazeera.com/Services/Rss/?PostingId=2007731105943979989. I get errors and when I check the response, I am told that "The requested URL '/reader/api/0/stream/contents/feed/{SUBSCRIPTION URL MINUS QUERY STRING}' was not found on this server". I know that somehow the query strings of the subscription URL and the request URL are getting mixed up. How can I get around this?

هل كانت مفيدة؟

المحلول

You want to Url Encode the Feed Url. There's an encoding in urls that converts any special character into a sequence of characters that won't interfere with query operations. You see this a lot when people use spaces, your browser will put %20.

In C# The place I know to find UrlEncode is HttpUtility.UrlEncode

Update

Yes the WebUtility.UrlEncode(string url) method will work too.

The idea is that when you have text you want to insert into an url, but you don't want it to affect the behavior/parsing of your url, you encode the text you want to insert. Obviously inserting one url into another will likely cause undesireable results, so the url you're putting into the {FEED URL} is what needs encoding.

Example:

// The ?, &, and :// will likely cause some interesting parsing by
// the target webserver.
var feedUrl = "http://site.com/url?a=1&b=2";

var serviceUrl = "https://www.google.com/reader/api/0/stream/contents/feed/{0}?ot=1253052000&r=n&xt=user/-state/com.google/read&n=20&ck=1255646178892&client=myApplication";

var resultUrl = string.Format(serviceUrl, WebUtility.UrlEncode(feedUrl));

Resulting url would be:

https://www.google.com/reader/api/0/stream/contents/feed/http%3A%2F%2Fsite.com%2Furl%3Fa%3D1%26b%3D2?ot=1253052000&r=n&xt=user/-state/com.google/read&n=20&ck=1255646178892&client=myApplication

Which should work for you just fine.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top