Skip to content

Commit e8279bf

Browse files
committed
Get proxy now passes through web exceptions
[otf:9364]
1 parent 83e5386 commit e8279bf

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

‎WebApp/Controllers/ApiController.cs‎

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
usingOnTimeApi;
77
usingSystem.Net;
88
usingAPIExample.FormsAuth;
9+
usingSystem.IO;
10+
usingSystem.Text;
911

1012
namespaceAPIExample.Controllers
1113
{
@@ -22,14 +24,30 @@ public ActionResult Get(string resource)
2224
// make an API call to OnTime
2325
varOnTime=GetOnTime();
2426

25-
varwebClient=newWebClient();
27+
varrequest=WebRequest.Create(OnTime.GetUrl(resource));
2628

27-
varresultString=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+
StreamresultStream;
30+
HttpWebResponseresponse;
31+
try
32+
{
33+
response=(HttpWebResponse)request.GetResponse();
34+
}catch(WebExceptione)
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+
3351
returnnull;
3452
}
3553

0 commit comments

Comments
(0)