问题描述
原来用的是MultipartPostMethod()封装的数据,现在要用c#来实现这一功能,希望高手解答,谢谢packagecom.meridian.cfets.lcm3.internal.noticemanagement;importjava.io.File;importjava.io.FileNotFoundException;importjava.io.FileOutputStream;importjava.io.IOException;importjava.util.Properties;importjava.util.Vector;importorg.apache.commons.httpclient.HttpClient;importorg.apache.commons.httpclient.HttpException;importorg.apache.commons.httpclient.HttpStatus;importorg.apache.commons.httpclient.methods.GetMethod;importorg.apache.commons.httpclient.methods.MultipartPostMethod;importcom.meridian.frame.utils.Utils;publicclassHttpsTool{privateHttpClientclient=null;privateMultipartPostMethodpostMethod=null;privateStringout="1";HttpsTool(){}publicbooleanstartHttps(){Stringpathtemp=this.getClass().getProtectionDomain().getCodeSource().getLocation().toString();Stringpathini=pathtemp.substring(6,pathtemp.lastIndexOf("bin/"))+"resource/";Stringurl=null;pathini="."+pathini.substring(pathini.indexOf("/plugin/"))+"httpsSetting.ini";PropertiesdbProps=null;try{System.out.println("httpssettingis"+pathini);dbProps=Utils.getProperties(pathini);url=dbProps.getProperty("https");out=dbProps.getProperty("displayInfor");}catch(Exceptione){System.out.println("读取配置文件出错,请核对配置文件设置");returnfalse;}try{client=newHttpClient();postMethod=newMultipartPostMethod(url);client.setConnectionTimeout(100000);postMethod.setRequestHeader("Content-type","multipart/form-data;charset=GB2312");}catch(Exceptiona){System.out.println("连接服务时出错。");returnfalse;}returntrue;}/****@param上传的文件名,包括路径*@return*@throwsHttpException*@throwsIOException*/publicbooleanuploadFile(Vectorfiles)throwsHttpException,IOException{booleanbak=false;postMethod.addParameter("exe","U");for(inti=0;i<files.size();i++){Filef=newFile((String)files.elementAt(i));Stringname=Paserpinyin.getPingYin(f.getName());postMethod.addParameter(f.getName(),f);System.out.println("upload:"+f.getAbsoluteFile());}intstatusCode1=client.executeMethod(postMethod);if(statusCode1!=HttpStatus.SC_OK){System.err.println("savefailed:"+postMethod.getStatusLine());bak=false;}else{System.out.println("Savesuccess:"+postMethod.getStatusLine());bak=true;}outDebug();returnbak;}这是源码,怎样用c#来实现这一功能?
解决方案
解决方案二:
使用.NET的WebClientWebRequest等对象。
解决方案三:
但是怎么封转数据呢?这个封装数据的格式我不明白,格式不正确后台无法解析。