Solved

create cross domain proxy page with asp.net

Posted on 2009-07-07
6
1,059 Views
Last Modified: 2012-05-07
Hello there,
I create a c# code according the link below to create a proxy page to get info from blip.tv

http://www.experts-exchange.com/Programming/Languages/Scripting/AJAX/Q_23622413.html?sfQueryTermInfo=1+asp.net+cross+domain+proxi

The code I have below works fine to get the details info from blip.tv but get wrong information with the playlist
url for detail list
http://www.blip.tv/file/2331487?skin=json
url for playlist
http://www.blip.tv/bookmarks/1990066?skin=json
Both link retrive correct info from web browser, but with the c# code, play list is not correct.
Any idea? Thanks ahead
string requestcontent;

        string responsecontent;

   

        string request = "http://blip.tv/bookmarks/1990066?skin=json";

        HttpWebRequest req=(HttpWebRequest)WebRequest.Create(request );

        req.Method = "POST";

        req.ContentType = "application/x-www-form-urlencoded";

     

        Stream sw = req.GetRequestStream();

        sw.Write(buffer, 0, buffer.Length);    

        sw.Close();
 

        HttpWebResponse WebResp = (HttpWebResponse)req.GetResponse();

        Stream sr = WebResp.GetResponseStream ();

        StreamReader sdr = new StreamReader(sr);

        responsecontent = sdr.ReadToEnd();
 

        responsecontent = responsecontent.Replace("]);", "]");     

        responsecontent = responsecontent.Substring(16, responsecontent .Length -16);

        Response .Write (responsecontent );

        sdr.Close();

        WebResp.Close();

Open in new window

0
Comment
Question by:tomcattyy
  • 4
  • 2
6 Comments
 
LVL 21

Expert Comment

by:MogalManic
Comment Utility
Try changing the Method to Get (line 6).
0
 
LVL 1

Author Comment

by:tomcattyy
Comment Utility
Hello MoqalManic,
I change the method to Get and get this runtime exception
System.Net.ProtocolViolationException: Cannot send a content-body with this verb-type.
on this line
Stream sw = req.GetRequestStream();
suggestions?
thanks

0
 
LVL 21

Accepted Solution

by:
MogalManic earned 500 total points
Comment Utility
Sorry,

I did not examine your sample close enough.  When you use the GET method you don't need lines 7-11(all of the information to request the data is in the URL).  So your code should look like this:
string requestcontent;

string responsecontent;
 

string request = "http://blip.tv/bookmarks/1990066?skin=json";

HttpWebRequest req=(HttpWebRequest)WebRequest.Create(request );

req.Method = "GET";
 

HttpWebResponse WebResp = (HttpWebResponse)req.GetResponse();

Stream sr = WebResp.GetResponseStream ();

StreamReader sdr = new StreamReader(sr);

responsecontent = sdr.ReadToEnd();
 

responsecontent = responsecontent.Replace("]);", "]");     

responsecontent = responsecontent.Substring(16, responsecontent .Length -16);

Response .Write (responsecontent );

sdr.Close();

WebResp.Close();

Open in new window

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Author Comment

by:tomcattyy
Comment Utility
Thanks MoqaManic,
I changed as suggest and it works as before. I start to suspect it's the source feed got problem, I send in one playlist number and It returned with all playlist with id=-1, I am contacting the blip.tv now to see if it is their problem.
the query is like below
http://blip.tv/bookmarks/179899?skin=json
I will got correct count in FF but not in IE, so after I place the query in c# code, the result is not correct.
Any input on this?
Thanks
0
 
LVL 1

Author Comment

by:tomcattyy
Comment Utility
Hello MogalManic,
obviously the json feed got problem, they suggest me to use Rss feed,
I remove some of the returncontent trimming line and I hope to see the whole xml content.
 but after I change the request string to a RSS feed. I got only the content, all  the xml tag was not shown as it should be here, below in code snippet is the one been returned.
Can you see something need to change? Thanks.

<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:blip="http://blip.tv/dtd/blip/1.0" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:amp="http://www.adobe.com/amp/1.0" xmlns:dcterms="http://purl.org/dc/terms" xmlns:gm="http://www.google.com/schemas/gm/1.1" xmlns:mediaad="http://blip.tv/dtd/mediaad/1.0" version="2.0">
<channel>
<title>tomcattyy : epicProp1 - blip.tv (beta)</title>
<link>http://blip.tv</link>
<description>tomcattyy : epicProp1 - blip.tv (beta)</description>
<language>en-us</language>
<generator>http://blip.tv</generator>
<lastBuildDate>Tue, 07 Jul 2009 20:52:55 +0000</lastBuildDate>
<pubDate>Tue, 07 Jul 2009 20:52:55 +0000</pubDate>

<item>
<guid isPermaLink="false">5600B332-6B37-11DE-8F7C-C8FB9814B35A</guid>
<link>http://blip.tv/file/2331487</link>
<title>property1</title>
<blip:user>tomcattyy</blip:user>
<blip:userid>408432</blip:userid>
<blip:safeusername>tomcattyy</blip:safeusername>
<blip:show>tomcattyy</blip:show>
<blip:showpage>http://tomcattyy.blip.tv/</blip:showpage>

<blip:picture>http://blip.tv/skin/blipnew/placeholder_user.gif</blip:picture>
<blip:posts_id>2351491</blip:posts_id>
<blip:item_id>2331487</blip:item_id>
<blip:item_type>file</blip:item_type>
<blip:contentRating>TV-UN</blip:contentRating>
<blip:rating>0.0</blip:rating>
<blip:datestamp>2009-07-07T20:47:07Z</blip:datestamp>
<blip:language>English</blip:language>
<blip:adChannel/>

<blip:recommendations>0</blip:recommendations>
<blip:recommendable>0</blip:recommendable>
<blip:adminRating/>
<blip:runtime>51</blip:runtime>
<blip:embedLookup>AYGPw2eY91Q</blip:embedLookup>
<blip:embedUrl type="application/x-shockwave-flash">http://blip.tv/play/AYGPw2eY91Q</blip:embedUrl>
<wfw:commentRss>http://blip.tv/comments/?attached_to=post2351491&amp;skin=rss</wfw:commentRss>
<blip:thumbnail_src>Tomcattyy-property1247-316.jpg</blip:thumbnail_src>
<blip:puredescription>House </blip:puredescription>

<blip:smallThumbnail>http://a.images.blip.tv/Tomcattyy-property1247-316-875.jpg</blip:smallThumbnail>
<blip:license>No license (All rights reserved)</blip:license>
<description>

http://blip.tv tomcattyy : epicProp1 - blip.tv (beta) en-us http://blip.tv Tue, 07 Jul 2009 20:52:55 +0000 Tue, 07 Jul 2009 20:52:55 +0000 5600B332-6B37-11DE-8F7C-C8FB9814B35A http://blip.tv/file/2331487 tomcattyy 408432 tomcattyy tomcattyy http://tomcattyy.blip.tv/ http://blip.tv/skin/blipnew/placeholder_user.gif 2351491 2331487 file TV-UN 0.0 2009-07-07T20:47:07Z English 0 0 51 AYGPw2eY91Q http://blip.tv/play/AYGPw2eY91Q http://blip.tv/comments/?attached_to=post2351491&skin=rss Tomcattyy-property1247-316.jpg House http://a.images.blip.tv/Tomcattyy-property1247-316-875.jpg No license (All rights reserved) <embed src="http://blip.tv/play/AYGPw2eY91Q" type="application/x-shockwave-flash" width="480" height="390" allowscriptaccess="always" allowfullscreen="true"></embed> <br /> House http://blip.tv/file/2331487 Default Category Tue, 07 Jul 2009 20:52:55 +0000 <embed src="http://blip.tv/play/AYGPw2eY91Q" type="application/x-shockwave-flash" width="480" height="390" allowscriptaccess="always" allowfullscreen="true"></embed> property1 30FA4B6C-6B31-11DE-A131-99B68C287762 http://blip.tv/file/2331301 tomcattyy 408432 tomcattyy tomcattyy http://tomcattyy.blip.tv/ http://blip.tv/skin/blipnew/placeholder_user.gif 2351289 2331301 file TV-UN 0.0 2009-07-07T20:03:08Z English 0 0 187 AYGPwh2Y91Q http://blip.tv/play/AYGPwh2Y91Q http://blip.tv/comments/?attached_to=post2351289&skin=rss Tomcattyy-mark1854-465.jpg this isthe video1 http://a.images.blip.tv/Tomcattyy-mark1854-465-932.jpg No license (All rights reserved) <embed src="http://blip.tv/play/AYGPwh2Y91Q" type="application/x-shockwave-flash" width="320" height="270" allowscriptaccess="always" allowfullscreen="true"></embed> <br /> <strong>this isthe video1<br /></strong> http://blip.tv/file/2331301 Citizen Journalism korean Tue, 07 Jul 2009 20:53:39 +0000 korean korean <embed src="http://blip.tv/play/AYGPwh2Y91Q" type="application/x-shockwave-flash" width="320" height="270" allowscriptaccess="always" allowfullscreen="true"></embed>mark1

Open in new window

0
 
LVL 1

Author Comment

by:tomcattyy
Comment Utility
It turned out to be the xml file displayed by browser is like that, all tag will be removed. It's working fine. Thanks.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now