Search code examples
c#httpwebrequesturifragment-identifier

WebRequest removing Fragment from the Uri


I want to open the following page:

http://www.google.com/search?q=dvd+player&tbm=shop&hl=en&aq=f#q=car+speaker+&hl=en&sa=X&ei=vbtSTqTPDKXniAKy0-iDAw&ved=0CC0QpwUoAA&tbs=cat:895%2Cprice%3A1%2Cppr_min%3A50%2Cppr_max%3A99.99&tbm=shop&tbo=&fp=1&biw=851&bih=426&cad=b&bav=on.2,or.r_gc.r_pw.

but when I try to open it using WebRequest class, it removes the "Fragment" (which is not a Uri Fragment in this case) from the url, and tries to open the following url instead:

http://www.google.com/search?q=dvd+player&tbm=shop&hl=en&aq=f

How can I do to open exactly that url?

I tried encoding the # character, but that does not seem to be working.

Edit:
I know what the URL is, what the fragment is, and all of it. What I'm asking is if there is a way to override what the Uri class does. (To take the Uri, and remove what is after # and place it in the Fragment property, etc), so I can query that url, instead of the modified url.


Solution

  • While the fragment in your example doesn't do exactly what a fragment was designed to do, it's still providing client-side data to the browser to take action after the page has been initially loaded. If you watch carefully when clicking on the link, you'll see the title of the page starts out as "dvd player" (from the original query string) but then changes to "car speaker" after the page has loaded from the server and the client-side script executes.