I tried to execute a Post Request with Postdata, which are partially urlencoded.
I have the following PostData to send:
p1=v1
p2=v2
p3=up1=uv1&up2=uv2
in order to achieve this, I format the value of p3
p3=up1%3duv1%26up2%3duv2
Then I write everything in one String value:
p1=v1&p2=v2&p3=up1%3duv1%26up2%3duv2
Now I have a Post Request:
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
request.Method = "POST";
byte[] data = Encoding.UTF8.GetBytes(postData);
request.ContentType = "application/x-www-form-urlencoded";
request.Headers["ContentLength"] = data.Length.ToString();
using (Stream stream = await request.GetRequestStreamAsync())
{
stream.Write(data, 0, data.Length);
}
WebResponse response = await request.GetResponseAsync();
Stream streamResponse = response.GetResponseStream();
But the target URL now receives
p1=v1
p2=v2
P3=up1=uv1_up2=uv2
a _ instead of & additionally and nevertheless I'm using UTF8 encoding Characters like äüö are broken.
I tried several encodings (ASCII, iso-8859-1) but always the same.
The final question is, how to post a urlencoded String?