http 文件流

来源:互联网 发布:mac机械键盘 编辑:程序博客网 时间:2024/06/08 18:48

HTTP 文件流:将文件解析成二进制数据流传送给对方。

举例:

java http post 同时发送文件流与数据


数据的话,直接“&参数名 =参数值”的形式即可,主要是文件流需要进行相应的定义,举例:以文件流的方式发送 和接收。
postData += ("&hashcode=" + GetMD5String(pwd));
byte[] data = System.Text.Encoding.UTF8.GetBytes(postData);
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("url");
myRequest.Method = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";//定义文件流形式,这个就是流的类型。
myRequest.ContentLength = data.Length;
Stream newStream = myRequest.GetRequestStream();
// 发送数据
newStream.Write(data, 0, data.Length);
newStream.Close();
// 接收
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
string content = reader.ReadToEnd();


0 0
原创粉丝点击