File tree Expand file tree Collapse file tree 1 file changed +24
-6
lines changed
Expand file tree Collapse file tree 1 file changed +24
-6
lines changed Original file line number Diff line number Diff line change 66using OnTimeApi ;
77using System . Net ;
88using APIExample . FormsAuth ;
9+ using System . IO ;
10+ using System . Text ;
911
1012namespace APIExample . Controllers
1113{
@@ -22,14 +24,30 @@ public ActionResult Get(string resource)
2224// make an API call to OnTime
2325var OnTime = GetOnTime ( ) ;
2426
25- var webClient = new WebClient ( ) ;
27+ var request = WebRequest . Create ( OnTime . GetUrl ( resource ) ) ;
2628
27- var resultString = webClient . DownloadString ( OnTime . GetUrl ( resource ) ) ;
28- Response . Write ( resultString ) ;
29- Response . ContentType = "application/json" ;
30- Response . ContentEncoding = System . Text . Encoding . UTF8 ;
31- Response . Charset = "UTF-8" ;
29+ Stream resultStream ;
30+ HttpWebResponse response ;
31+ try
32+ {
33+ response = ( HttpWebResponse ) request . GetResponse ( ) ;
34+ } catch ( WebException e )
35+ {
36+ response = ( HttpWebResponse ) e . Response ;
37+ }
3238
39+ resultStream = response . GetResponseStream ( ) ;
40+
41+ Response . ContentType = response . ContentType ;
42+ try
43+ {
44+ Response . ContentEncoding = Encoding . GetEncoding ( response . ContentEncoding ) ;
45+ } catch ( Exception ) { }
46+
47+ Response . Charset = response . CharacterSet ;
48+
49+ resultStream . CopyTo ( Response . OutputStream ) ;
50+
3351return null ;
3452}
3553
You can’t perform that action at this time.
0 commit comments