I need to send the following text to a web application (MVC2)
Hello <>~!@#$%^&*()_+|}{":?><
Hello <>?:"P{{}|+)_)_&*()&^*^%&#%^@#$~!@#~!@#~Q
I'm sending this by a UWP app using Windows.Web.Http.HttpClient. However, when this message received from the web it throws an exception.
"A potentially dangerous Request.Form value was detected from the client (data="..._&*()&^*^%&#%^@#$~!@#~!@#~Q")."
The same message can be sent by Android and iOS apps and web server accepts it with no issue. Can someone help me to solve this without any server-side modification?
Here is the code I used on UWP app. Please let me know if need any alteration in here. Thanks again.
var httpBaseProtocolFilter = new HttpBaseProtocolFilter();
httpBaseProtocolFilter.MaxVersion = HttpVersion.Http20;
HttpClient httpClient = new HttpClient(httpBaseProtocolFilter);
var requestUrl = Global.ServerUrl;
httpClient = SetHeaders(httpClient);
httpClient.DefaultRequestHeaders.Accept.Add(new HttpMediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"));
HttpResponseMessage response = null;
if (requestMehtod == ApplicationConstants.RequestType.POST) //Request type POST
{
if (postData != null && postData.Count > 0)
{
Dictionary<string, string> pairs = new Dictionary<string, string>();
foreach (var item in postData)
{
val = (String.IsNullOrWhiteSpace(item.Value)) ? "" : item.Value;
pairs.Add(item.Key, val);
}
Uri uri = new Uri(requestUrl);
HttpFormUrlEncodedContent formContent = new HttpFormUrlEncodedContent(pairs);
response = await httpClient.PostAsync(uri, formContent).AsTask(cts.Token);
}
}
responseText = await response.Content.ReadAsStringAsync();