我有些资料,是关于HTTP上传图片的原理,不知道能不能帮到你什么,^_^
如下:1、图片提交(client,HTML)
<html><body><form ation="upload.asp" method="post" enctype="multipart/form-data">
<input name="pic" type="file" id="pic"><br>
<input type="submit" name="Submit" value="提交">
</form></body></html>2、图片接收(server,ASP)
<%
function StringToBinary(String)’自定义函数,将字符串转化为二进制。
Dim i, b
For i=1 to len(String)
b = b & ChrB(Asc(Mid(String,i,1)))
Next
StringToBinary = b
End function
data=Request.BinaryRead(request.TotalBytes)’从客户端读取所有数据
ct=Request.Servervariables("HTTP_Content_Type")
Boundary ="--"&Mid(ct, InStr(LCase(ct), "boundary=") + 9)
str2=StringToBinary("image/bmp")
start=instrb(data,str2)+13’图片信息的开始字节
if start=13 then
str2=StringToBinary("image/gif")
start=instrb(data,str2)+13
end if
if start=13 then
str2=StringToBinary("image/pjpeg")
start=instrb(data,str2)+15
end if
str3=StringToBinary(Boundary)
tend=instrb(10,data,str3)’图片信息的结束字节
leng=tend-start’图片信息的长度
rdata=midb(data,start,leng)’取出图片信息 ……%>
如下:1、图片提交(client,HTML)
<html><body><form ation="upload.asp" method="post" enctype="multipart/form-data">
<input name="pic" type="file" id="pic"><br>
<input type="submit" name="Submit" value="提交">
</form></body></html>2、图片接收(server,ASP)
<%
function StringToBinary(String)’自定义函数,将字符串转化为二进制。
Dim i, b
For i=1 to len(String)
b = b & ChrB(Asc(Mid(String,i,1)))
Next
StringToBinary = b
End function
data=Request.BinaryRead(request.TotalBytes)’从客户端读取所有数据
ct=Request.Servervariables("HTTP_Content_Type")
Boundary ="--"&Mid(ct, InStr(LCase(ct), "boundary=") + 9)
str2=StringToBinary("image/bmp")
start=instrb(data,str2)+13’图片信息的开始字节
if start=13 then
str2=StringToBinary("image/gif")
start=instrb(data,str2)+13
end if
if start=13 then
str2=StringToBinary("image/pjpeg")
start=instrb(data,str2)+15
end if
str3=StringToBinary(Boundary)
tend=instrb(10,data,str3)’图片信息的结束字节
leng=tend-start’图片信息的长度
rdata=midb(data,start,leng)’取出图片信息 ……%>
解决方案 »
- webBrowser 未将对象引用设置到对象的实例,问题在哪呀?
- 关于扑克牌类库的问题
- 如何实现优先队列?
- 关于datagrid的数据保存问题.
- SqlServer中存储一段视频怎么操作?
- 在一个页面基础上弹出对话框进行信息添加后,如何刷新原页面
- 在.NET2003中引入MSFlexGrid这个ocx控件时,报错说没有ActiveX许可证,这是怎么回事啊?
- image显示图像问题
- 谁有c#开发media services的插件的资料
- ExecuteReader 要求已打开且可用的 Connection。连接的当前状态为已关闭。请问大佬知道这个是什么原因吗?
- 希望认识做界面美工的朋友!与大家交流美工制作!请留下MSN或者QQ!
- 求C#发邮件的代码。。
http://www.west-wind.com/presentations/dotnetWebRequest/dotnetWebRequest.htm
there is a section on how to upload files
访问外网服务器时。外网服务器网站有上传功能就行了!
选择附件:
<input id="upload" style="WIDTH: 360px; HEIGHT: 22px" type="file" size="56" name="upload" class="edline" runat="server">
后台:
private void iBtnOk_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
int FileLength=0;
System.Web.HttpPostedFile UpFile=upload.PostedFile ;
FileLength=UpFile.ContentLength ;
string strFileName= UpFile.FileName.Substring(UpFile.FileName.LastIndexOf("\\")+1);
byte[] FileData=new byte[FileLength];
if (FileLength!=0)
{ System.IO.Stream FileStream=UpFile.InputStream;
FileStream.Read(FileData ,0,FileLength );//读入文件
}
//加到数据库
tmpDoc.add_DcC(DataAccess.common.IntNull(tbxOrderNum.Text),strFileName,FileData,tbxMemo.Text,int.Parse(ViewState["docId"].ToString()));
getDBImage(FileData,strFileName);
}public string getDBImage(byte[] buffer,string fileName)
{
string strPath=System.Web.HttpContext.Current.Server.MapPath("\\DataPlat\\tempFile\\" + fileName );
//WriteToFile(strPath,ref tempFileImage.fileImage ); // Create a file
FileStream newFile = new FileStream(strPath, FileMode.Create); // Write data to the file
newFile.Write(buffer , 0, buffer.Length ); // Close file
newFile.Close(); return strPath;
}
对于WinForm我想一定要有client 和Server
有个建议!
在WinForm中开个子窗口!可以访问Web页面 的!现在有一些叫网络硬盘的!
他们的原理其实也是C/S的!要装客户端控件,通过客户端控件访问服务器!
而且不是用的80端口!http通常用80端口!
设到你要上传的服务器端接收文件的url。
条件是外网服务器上已有上传文件的Web页面。
string lcUrl = "http://www.west-wind.com/testpage.wwd";HttpWebRequest loHttp = (HttpWebRequest) WebRequest.Create(lcUrl); // *** Send any POST datastring lcPostData = "Name=" + HttpUtility.UrlEncode("Rick Strahl") + "&Company=" + HttpUtility.UrlEncode("West Wind "); loHttp.Method="POST";byte [] lbPostBuffer = System.Text. Encoding.GetEncoding(1252).GetBytes(lcPostData);loHttp.ContentLength = lbPostBuffer.Length; Stream loPostData = loHttp.GetRequestStream();loPostData.Write(lbPostBuffer,0,lbPostBuffer.Length);loPostData.Close(); HttpWebResponse loWebResponse = (HttpWebResponse) loHttp.GetResponse(); Encoding enc = System.Text.Encoding.GetEncoding(1252); StreamReader loResponseStream = new StreamReader(loWebResponse.GetResponseStream(),enc); string lcHtml = loResponseStream.ReadToEnd(); loWebResponse.Close();loResponseStream.Close();-------------------------------------------------
// pass Proxy string and bypass local machineWebProxy loProxy = new WebProxy("http://proxy-server.mine.com:8080",true); // ** ByPassListstring[] cByPass = new string[2];cByPass[1] = "http://someserver.net";cByPass[2] = http://192.0.0.1 loProxy.BypassList = cByPass; // ** Proxy AuthenticationloProxy.Credentials = new NetworkCredential("proxyusername","pass"); Request.Proxy = loProxy;
怎么解决呢???
我睡觉前再顶一下吧!!!!!
http://www.aspheute.com/english/20000802.asp客户端编码可以参考
Retrieving HTTP content in .NET
http://www.west-wind.com/presentations/dotnetWebRequest/dotnetWebRequest.htm里面的那个HTTP file upload method for multi-part forms例子详述了怎么基于multipart/form-data的enctype 数据格式, 来上传文件数据格式参考
http://www.aspzone.com/articles/160.aspx#ParsingRequest
这是怎么回事啊