Search code examples
c#webclientwebclient.uploaddata

C# WebClient.UploadData


I'm a .NET newbie and I'm playing with the WebClient class to consume a simple rest service. What I need to do is post a file to the service with some parameters in QueryString. The WebClient provides the QueryString NameValueCollection which is designed exactly to pass parameters in a QueryString and it works JUST on Get methods so in my case the QueryString collection doesn't fit because while uploading the file the WebClient is actually doing a POST. So I'm stuck. Any ideas? thank you in advance.


Solution

  • You can pass the query string parameters in the address parameter for UploadData:

    client.UploadData("http://my.server.com/service?id=1&name=foo", myData);