110,536
社区成员
发帖
与我相关
我的任务
分享
Stream oStream;
string postData;
HttpWebRequest myRequest;
BinaryReader oReader;
string imgWebsite = @"http://192.168.169.11/service/deal_image_service.php";
postData = "command=UPLOAD"; //参数1
postData += "&id="; //参数2
postData += "&image_name=imgtest1" ; //参数3
postData += "&image_type=0" ; //参数4
postData += "&poi_id=111" ; //参数5
postData += "&temp_id=3"; //参数6
postData += "&file="; //参数7,这个后面跟的就是图片内容了
byte[] pardata = Encoding.Default.GetBytes(postData);
//oStream = img.GetFileContent();
oStream = new FileStream(@"D:\DotNetNuke_Install\Upload\title_canyin.jpg",FileMode.Open, FileAccess.Read);
oReader = new BinaryReader(oStream);
byte[] imgdata = oReader.ReadBytes(Convert.ToInt32(oStream.Length));
byte[] data = new byte[postData.Length + imgdata.Length];
//把前面的字符串和图片的byte数组连起来,这样做对么????
pardata.CopyTo(data, 0);
imgdata.CopyTo(data, pardata.Length);
myRequest = (HttpWebRequest)WebRequest.Create(imgWebsite);
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 findokID = reader.ReadToEnd();