I'm having an issue with HttpClient
in Visual Studio C#.
I was trying to make a GetStringAsync
request with HttpClient
but the response is not formatted as expected.
The request is like phpfile.php?readmode=yes, it displays the text file response but it is not formatted well as shown below:
hello
hello
but it displays:
hellohello
I searched the internet for almost 2 hours and I am still confused, here is the code
string url = URL;
var responseString = await client.GetStringAsync(url);
and then I am adding it to a textbox (as this is some kind of msg client):
f1.msglog.Text = f1.msglog.Text + Environment.NewLine + responseString.ToString();
It could be an issue with different types of line endings. Try standardizing the line endings with this:
responseString.Replace("\r\n", "\n").Replace("\r", "\n").Replace("\n", Environment.NewLine)
By the way, don't call ToString. This was already a string, so calling ToString does nothing.