How to create an POST with the HttpWebRequest Class in VB.net (2008)? I can find exemples with text only but not with text and files. Thanks.
A:
You should be able to read the file in a buffer, and upload it to the server. It is not that difficult.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.Method "POST";
Stream fileStream = File.OpenRead("filename");
byte [] buffer = new byte[1024];
Stream reqStream = request.GetRequestStream();
int read = fileStream.Read(buffer, 0, buffer.Length);
while(read > 0)
{
reqStream.Write(buffer,0,read);
read fileStream.Read(buffer, 0, buffer.Length);
}
reqStream.Close();
fileStream.Close();
// now get the response...
Does that help?
feroze
2009-11-11 01:53:48
Thank you, but an example in vb.net would help me more.
tobiasre
2009-11-11 14:16:34
I am sure you can find a VB.net sample on MSDN. In any case, you can make it even simpler. Just use WebClient.WebClient client = new WebClient();client.UploadFile(...)
feroze
2009-11-11 14:58:31
Yes, WebClient() is simpler, but it isn´t possible to make a POST with text + files (in one POST) in this Class.
tobiasre
2009-11-11 18:37:50
MSDN: http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest(VS.71).aspx I think its a good help but no example .
tobiasre
2009-11-11 18:43:51