I’m attempting to send an image and some text to a server at the same time.
I’m using WebRequest like the following to send text:
Dim ba As Byte() = Encoding.UTF8.GetBytes(query)
Dim wr As WebRequest = WebRequest.Create(Me.server_url)
wr.Method = "POST"
wr.ContentType = "application/x-www-form-urlencoded"
wr.ContentLength = ba.Length
And I have the following using WebClient for sending an image:
System.Net.WebClient Client = new System.Net.WebClient();
Client.Headers.Add("Content-Type", "binary/octet-stream");
byte[] result = Client.UploadFile(Properties.Settings.Default.script_url,
"POST", "desktop.png");
But I cannot figure out how to do both at the same time.
After lots of searching, I found the following link:
http://www.paraesthesia.com/archive/2009/12/16/posting-multipartform-data-using-.net-webrequest.aspx
It is for C#, so here is a proof of concept I put together for VB:
This, of course, is geared toward my personal needs, but I think it describes well what needs to be done. For the image, there is a filename. In this case, it is not an actual file. But the PHP receiving the file needs the data.
Here is the PHP code I used to test this:
?>
take care,
lee