VB.NET POST图片到 asp.net页面,是否用request.form["file"]取,如果是为什么会乱码~如果是编码问题那又怎么解决呢???现附上vb.net源码,,,帅哥哥们帮一下小弟吧.....

问题描述

PublicFunctionpostCaptcha(ByValstrApiKeyAsString,ByValstrCaptchaFileAsString)AsStringDimobjEncodingAsNewSystem.Text.UTF8EncodingDimobjStreamWriterAsSystem.IO.StreamWriterDimobjStreamAsSystem.IO.StreamDimobjHTTPRequestAsHttpWebRequestDimsbPostDataAsNewSystem.Text.StringBuilderDimintUploadBitAsIntegerDimintUploadSoFarAsIntegerDiminttoUploadAsIntegerDimiAsIntegerDimobjStreamReaderAsSystem.IO.StreamDimstrResultAsString'setrequestpropertiesobjHTTPRequest=System.Net.WebRequest.Create("http://www.captcha4u.com/api.aspx")objHTTPRequest.AllowAutoRedirect=TrueobjHTTPRequest.Accept="*/*"objHTTPRequest.UserAgent="Mozilla/4.0(compatible;MSIE6.0;WindowsNT5.1;.NETCLR1.0.3705)"objHTTPRequest.KeepAlive=FalseobjHTTPRequest.Timeout=30000objHTTPRequest.Method="POST"objHTTPRequest.ContentType="multipart/form-data;boundary=7cf2a327f01ae"sbPostData.Append("--"+"7cf2a327f01ae"+vbCrLf)sbPostData.Append("Content-Disposition:form-data;name=""api_key"""+vbCrLf)sbPostData.Append(vbCrLf)sbPostData.Append(strApiKey+vbCrLf)sbPostData.Append("--"+"7cf2a327f01ae"+vbCrLf)sbPostData.Append("Content-Disposition:form-data;name=""expire"""+vbCrLf)sbPostData.Append(vbCrLf)sbPostData.Append("1000"+vbCrLf)'defaultedto1000butyoucanchangethissbPostData.Append("--"+"7cf2a327f01ae"+vbCrLf)sbPostData.Append("Content-Disposition:form-data;name=""method"""+vbCrLf)sbPostData.Append(vbCrLf)sbPostData.Append("upload_captcha"+vbCrLf)sbPostData.Append("--"+"7cf2a327f01ae"+vbCrLf)sbPostData.Append("Content-Disposition:form-data;name=""rights"""+vbCrLf)sbPostData.Append(vbCrLf)sbPostData.Append("false"+vbCrLf)'defaultedtofalsebutyoucanchangethis'thisistheheaderforourcaptchafileuploadsbPostData.Append("--"+"7cf2a327f01ae"+vbCrLf)sbPostData.Append("Content-Disposition:form-data;name=""file"";filename="""&strCaptchaFile&""+vbCrLf)sbPostData.Append("Content-Type:image/pjpeg"+vbCrLf)sbPostData.Append(vbCrLf)'readourcaptchintoabytearrayDimobjBinReaderAsNewBinaryReader(File.OpenRead(strCaptchaFile))DimbytPhotoContentsAsByte()=objBinReader.ReadBytes(objBinReader.BaseStream.Length)objBinReader.Close()'convertourotherpostdataintoabytearrayDimbytPostContentsAsByte()=objEncoding.GetBytes(sbPostData.ToString)'createafooterforinsertationafterthefilebytesareuploadedDimbytPostFooterAsByte()=objEncoding.GetBytes(vbCrLf+"--"+"7cf2a327f01ae"+vbCrLf)'createanewdatabuffertoholdallofourbytearraysDimbytDataBufferAsByte()=NewByte(bytPostContents.Length+bytPhotoContents.Length+bytPostFooter.Length){}'copythecontentsofourthreebytearraysintooursinglebytearraySystem.Buffer.BlockCopy(bytPostContents,0,bytDataBuffer,0,bytPostContents.Length)System.Buffer.BlockCopy(bytPhotoContents,0,bytDataBuffer,bytPostContents.Length,bytPhotoContents.Length)System.Buffer.BlockCopy(bytPostFooter,0,bytDataBuffer,bytPostContents.Length+bytPhotoContents.Length,bytPostFooter.Length)'setthecontentlengthbasedonournewbytearraylengthobjHTTPRequest.ContentLength=bytDataBuffer.Length'getourstreamandpostourdataobjStream=objHTTPRequest.GetRequestStream()'chunkupourdataanduploadittoourstream'willgenerallyonlyneedtosendinonechunkunlessfileislargeintUploadBit=Math.Max(bytDataBuffer.Length/100,50*1024)intUploadSoFar=0Whilei<bytDataBuffer.LengthinttoUpload=Math.Min(intUploadBit,bytDataBuffer.Length-i)intUploadSoFar+=inttoUploadobjStream.Write(bytDataBuffer,i,inttoUpload)i=i+intUploadBitEndWhile'closeourstreamobjStream.Close()'gettheresponsefromtheserverDimobjHTTPResponseAsHttpWebResponse=CType(objHTTPRequest.GetResponse(),HttpWebResponse)objStreamReader=objHTTPResponse.GetResponseStream()'finalresultfromserverisreturnedtostrResultDimobjStreamResultAsNewSystem.IO.StreamReader(objStreamReader)strResult=objStreamResult.ReadToEnd'closeourobjectsobjStreamReader.Close()objStreamResult.Close()ReturnstrResultEndFunction//以下为调用源码PrivateSubbtnPostCaptcha_Click(ByValsenderAsObject,ByValeAsSystem.EventArgs)HandlesbtnPostCaptcha.ClickIftxtAPIKey.Text=""OrtxtCaptchaImage.Text=""ThenMsgBox("APIKeyandCaptchaImagefilemustbespecified")ExitSubEndIftxtCaptchaID.Text=postCaptcha(txtAPIKey.Text,txtCaptchaImage.Text)'stripoutoursucessindicatortojustgetthecaptchaIDIfInStr(txtCaptchaID.Text,"SUCCESS:captcha_id=",CompareMethod.Text)>0ThentxtCaptchaID.Text=Replace(txtCaptchaID.Text,"SUCCESS:captcha_id=","")txtCaptchaID.Text=Replace(txtCaptchaID.Text,vbCr,"")txtCaptchaID.Text=Replace(txtCaptchaID.Text,vbLf,"")cmdGetResult.Enabled=TrueElseMsgBox("Erroruploadingcaptcha.APIResult:"&txtCaptchaID.Text)cmdGetResult.Enabled=FalseEndIfEndSub

解决方案

解决方案二:
nalresultfromserverisreturnedtostrResultDimobjStreamResultAsNewSystem.IO.StreamReader(objStreamReader,Encoding.GetEncoding("GB2312"))strResult=objStreamResult.ReadToEnd指定格式就可以了
解决方案三:
谢谢你,但是在asp.net是怎么还原的呢?????是用request.form["file"].tostring()这这样吗?

时间: 2024-09-19 08:16:35

VB.NET POST图片到 asp.net页面,是否用request.form[&amp;quot;file&amp;quot;]取,如果是为什么会乱码~如果是编码问题那又怎么解决呢???现附上vb.net源码,,,帅哥哥们帮一下小弟吧.....的相关文章

框架源码核心-师傅们帮我普及一下----apache

问题描述 师傅们帮我普及一下----apache 例如:我想用eclipse运行apache mina 源码,顺便做个调试,源码里面有好多分支,每个分支为一个单独的子项目,当我把所有的这些分之都导入eclipse时,报错,运行不了,希望看到我提问的好朋友能帮我解决一下这个问题,有机会我当面重谢: 解决方案 你需要下载对饮的源码,然后Eclipse打开,设置好编译环境,然后编译. 解决方案二: 出错一般还是你的配置不对,多参考自带的帮助说明文档

高手~前辈救命啊,,,,,,我这里出现索引出错~~~也就是没有取到&amp;amp;quot;file&amp;amp;quot;=&amp;amp;gt;&amp;amp;gt;post 图片文件流到asp.net一个页面...怎么在这个页面取到正确的图片二进制流并还原......代码见内容!!!!!

问题描述 这是客户端代码vb.netPublicFunctionpostCaptcha(ByValstrApiKeyAsString,ByValstrCaptchaFileAsString)AsStringDimobjEncodingAsNewSystem.Text.UTF8EncodingDimobjStreamWriterAsSystem.IO.StreamWriterDimobjStreamAsSystem.IO.StreamDimobjHTTPRequestAsHttpWebReques

解决java 查看JDK中底层源码的实现方法_java

1.点 "window"-> "Preferences" -> "Java" -> "Installed JRES"2.此时"Installed JRES"右边是列表窗格,列出了系统中的 JRE 环境,选择你的JRE,然后点边上的 "Edit...", 会出现一个窗口(Edit JRE)3.选中rt.jar文件的这一项:"c:\program files\ja

ios 嵌套html5网页,&amp;amp;lt;input type=&amp;amp;quot;file&amp;amp;quot;&amp;amp;gt;。在ipad中选择打开相机照相后,页面刷新了

问题描述 ios嵌套html5网页,<inputtype="file">.在ipad中选择打开相机照相后,页面刷新了.在ipad浏览器中直接浏览就可以获得图片,网页也不会刷新. 解决方案 解决方案二:没有明白楼主问的是什么,还是楼主在讲述自己是怎么完成的解决方案三:我也碰到了,页面第一次使用相机就这样,第二次就不会,暂时没找到解决办法.解决方案四:感觉好像是说在ipad上获取图片时,先用相机拍照,这时候会刷新页面--

jsp问题-jsp如何获取页面&amp;amp;lt;input type=&amp;amp;quot;file&amp;amp;quot; /&amp;amp;gt;里面的路径

问题描述 jsp如何获取页面<input type="file" />里面的路径 jsp如何获取页面里面的路径 解决方案 页面里面的路径?不懂你的问题....

aspnet.mvc &amp;amp;lt;input type=&amp;amp;quot;file&amp;amp;quot; name=&amp;amp;quot;files&amp;amp;quot; multiple=&amp;amp;quot;multiple&amp;amp;quot; /&amp;amp;gt; 多图片上传

问题描述 html<inputtype="file"name="files"multiple="multiple"/>实现多图片上传,为什么只能接到一个图片,在后台(mvc)中如何接收<p><label>请选择一个图像文件:</label><inputtype="file"multiple="multiple"id="demo_input&qu

Acegi源码研究(五):七剑下天山

在Acegi初体验及初解剖(http://rmn190.javaeye.com/blog/332711)里, 通过对web.xml和applicationContext-acegi-security.xml的跟踪,我们得出被Acegi拦截下的请求最终交到了filterInvocationDefinitionSource配置下的几个Filter的实现类来处理. 它们是怎么处理这个请求的呢? 在Acegi(三): Acegi? Who are you? ,我们听说江湖中有"七剑", 但这么

iOS内存管理和malloc源码解读

最近由于排查问题,顺便对iOS的内存管理,尤其是malloc库稍微深入地了解一下,在这里整理出来,和大家分享一下. 0. iOS内存基本原理 在接触iOS开发的时候,我们都知道"引用计数"的概念,也知道ARC和MRR,但其实这仅仅是对堆内存上对象的内存管理.用WWDC某Session里的话说,这其实只是内存管理的冰山一角. 在内存管理方面,其实iOS和其它操作系统总体上来说是大同小异的,大的框架原理基本相似,小的细节有所创新和不同. 和其它操作系统上运行的进程类似,iOS App进程的

开源Asp.Net MVC网上商城BrnShop正式发布,提供源码下载(非官方文章)

BrnShop网上商城是以Asp.Net mvc3为基础开发的网上商城,源代码完全开源(企业版的源代码目前还没有完全整理完成,一旦整理完成也全部开源). 源码下载地址: asp.net(c#)开源商店系统Brn shop 1.9(免费仿京东商城) asp.net(c#)开源商店系统Brn shop 2.1(免费仿京东商城) 项目结构图如下: 后台管理页面: 功能简介: 1 基本数据:品牌,分类,属性(有些属性用作sku,有些属性还要提供商品筛选功能). 2 商品属性:商品图库,商品属性列表,商品