I'm using this code to send parameters to a webpage and getting correct response from it.
System.Net.WebClient oWeb = new System.Net.WebClient();
oWeb.Proxy = System.Net.WebRequest.DefaultWebProxy;
oWeb.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
oWeb.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
byte[] bytArguments = System.Text.Encoding.ASCII.GetBytes("value1=123&value2=xyz");
byte[] bytRetData = oWeb.UploadData("http://website.com/file.php", "POST", bytArguments);
response = System.Text.Encoding.ASCII.GetString(bytRetData);
But now I want to send a file like (.doc
) to it + above parameters(value1
, value2
), but I don't know how to do that.
Use WebClient.QueryString to pass name/value pairs associated with the request.
Copied from SO but can't remember it's link. And this is how it will be used
Here
@filepath
is the path of your file you want to upload: c:\file_to_upload.doc Andfile
is the name of the filed used in php as $_Files['file']