2
2
using System . Net ;
3
3
using System . Net . Http ;
4
4
using System . Net . Http . Formatting ;
5
+ using System . Text ;
5
6
using System . Web . Http ;
6
7
7
8
namespace WebApiHttpAuthService . Controllers
8
9
{
9
10
[ RoutePrefix ( "auth" ) ]
10
11
public class AuthController : ApiController
11
12
{
13
+ // Note: the following is necessary to ensure that no
14
+ // BOM is part of the response
15
+ private static readonly encoding = new UTF8Encoding ( false ) ;
12
16
13
- [ Route ( "user" ) ]
17
+ [ Route ( "user" ) ]
14
18
[ HttpPost ]
15
19
public HttpResponseMessage user ( FormDataCollection form )
16
20
{
@@ -34,7 +38,7 @@ public HttpResponseMessage user(FormDataCollection form)
34
38
}
35
39
36
40
var resp = new HttpResponseMessage ( HttpStatusCode . OK ) ;
37
- resp . Content = new StringContent ( content , System . Text . Encoding . UTF8 , "text/plain" ) ;
41
+ resp . Content = new StringContent ( content , encoding , "text/plain" ) ;
38
42
return resp ;
39
43
}
40
44
@@ -62,7 +66,7 @@ public HttpResponseMessage vhost(FormDataCollection form)
62
66
}
63
67
64
68
var resp = new HttpResponseMessage ( HttpStatusCode . OK ) ;
65
- resp . Content = new StringContent ( content , System . Text . Encoding . UTF8 , "text/plain" ) ;
69
+ resp . Content = new StringContent ( content , encoding , "text/plain" ) ;
66
70
return resp ;
67
71
}
68
72
@@ -96,7 +100,7 @@ public HttpResponseMessage resource(FormDataCollection form)
96
100
97
101
98
102
var resp = new HttpResponseMessage ( HttpStatusCode . OK ) ;
99
- resp . Content = new StringContent ( content , System . Text . Encoding . UTF8 , "text/plain" ) ;
103
+ resp . Content = new StringContent ( content , encoding , "text/plain" ) ;
100
104
return resp ;
101
105
}
102
106
@@ -129,7 +133,7 @@ public HttpResponseMessage topic(FormDataCollection form)
129
133
}
130
134
131
135
var resp = new HttpResponseMessage ( HttpStatusCode . OK ) ;
132
- resp . Content = new StringContent ( content , System . Text . Encoding . UTF8 , "text/plain" ) ;
136
+ resp . Content = new StringContent ( content , encoding , "text/plain" ) ;
133
137
return resp ;
134
138
}
135
139
0 commit comments