frenchie
frenchie

Reputation: 52047

Get raw querystring of WebClient in C#

I'm using a WebClient to make a POST request with a query string but I can't see the raw string. This is what I have:

WebClient TheWebClient = new WebClient();

TheWebClient.QueryString.Add("Param1", "1234");
TheWebClient.QueryString.Add("Param2", "4567");
TheWebClient.QueryString.Add("Param3", "4539");

var TheResponse = TheWebClient.UploadValues("https://www.example.com/posturl", "POST", TheWebClient.QueryString);

string TheResponseString = TheWebClient.Encoding.GetString(TheResponse);

//problem is that this only shows the keys
var RawQueryString = TheWebClient.QueryString;

How can I see the actual raw query string?

Upvotes: 0

Views: 1245

Answers (1)

Orel Eraki
Orel Eraki

Reputation: 12196

WebClient.UploadValues doesn't save the request "raw query string" simply because you provided it with them, and it's not gonna change, thus is redundant.

Furthermore, HttpPost requests doesn't use query string for the request payload, it has a url, a message payload; which is appended after the headers, maybe query string. Thus there is nothing new the client class should let you know, so it won't save it.

Upvotes: 2

Related Questions