I have a string eg CommentText = " This i$ @ b@d $+rin&"
. I want to include it as it is while creating a post request. Iam doing something like so:-
public async Task<string> PostComment(string hostUrl, string accountName, string key, string newsSourceId, string articleGuid, string newsId, string commentText, string authorDisplayName)
{
string url = EndPoints.PostCommentsURL;
bool isCommented = false;
string paramString = "HostUrl=" + hostUrl + "&AccountName=" + accountName + "&Key=" + key + "&newsSourceId=" + newsSourceId + "&articleGuid=" + articleGuid + "&articleId=" + newsId + "&commentText=" + commentText + "&authorDisplayName=" + authorDisplayName;
var content = new StringContent(paramString, Encoding.UTF8, "application/json");
content.Headers.Clear();
content.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
HttpClientHandler handler = new HttpClientHandler();
HttpClient httpClient = new HttpClient(handler);
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, url);
try
{
HttpResponseMessage response = await httpClient.PostAsync(url, content);
switch (response.StatusCode)
{
case HttpStatusCode.OK:
receiveStream = await response.Content.ReadAsStringAsync();
break;
case HttpStatusCode.Forbidden:
receiveStream = "UserInvalid";
break;
default:
receiveStream = null;
break;
}
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine(e.Message.ToString());
}
return receiveStream;
}
My issue is, while the request is sent, only the string before the special characters goes to the server and the special characters cant be seen. How can I include these characters as the part of the string.