开发者

HttpWebRequest Class Text + File in Vb.net

How to create an POS开发者_开发百科T with the HttpWebRequest Class in VB.net (2008)? I can find exemples with text only but not with text and files. Thanks.


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜