You are using AppendLine
, which is adding in carriage returns (new lines) to your string, this can be seen with the %0d
in your url string.
Simply change your logic to use the string builder Append
method.
Example would be:
if (!QueryString1.IsNullOrEmpty())
{
SB.Append(QueryString1);
}
edit: or if you want to encode only the parameters.
if (!QueryString1.IsNullOrEmpty())
{
SB.Append(HttpUtility.UrlEncode(QueryString1));
}
I think it can be done either way, the docs at http://msdn.microsoft.com/en-us/library/h10z5byc.aspx say it can be used to encode the entire URL