Solved

create cross domain proxy page with asp.net

Posted on 2009-07-07
6
1,062 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
ID: 24803490
Try changing the Method to Get (line 6).
0
 
LVL 1

Author Comment

by:tomcattyy
ID: 24805835
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
ID: 24806650
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:tomcattyy
ID: 24808184
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
ID: 24809369
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&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
ID: 24816629
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Loop not working 29 48
How do ASP.NET and MVC work together? 4 30
convert html to string 6 22
C# Comparing String Arrays. 5 28
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

861 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

30 Experts available now in Live!

Get 1:1 Help Now