public boolean updateLogisticToDangDang(String dir , File fileXML){
StringBuffer url = new StringBuffer();
url.append("http://api.dangdang.com/v2/sendGoods.php");
url.append("?gShopID="+DangDangConstant.gShopID);
PostMethod post = new PostMethod(url.toString());
//post.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
post.setRequestHeader( "Content-type" , "text/xml; charset=GBK" );
post.setRequestHeader("Accept-Language","zh-cn");
post.setRequestHeader("Connection","Keep-Alive");
try {
// 生成validateString 验证码
StringBuffer rev = new StringBuffer();
rev.append(DangDangConstant.gShopID);
rev.append(DangDangConstant.key);
String md5String = Md5Util.makeMd5Sum(ChangeToGBK.toGBK(rev.toString()).getBytes());
File file = new File(dir);
if (!file.exists()) {
return false;
}
// FilePart:用来上传文件的类
FilePart fp = new FilePart("sendGoods", file); //Part:类专门用来上传文件,其子类 ,FilePart:用来上传文件的类 StringPart:普通的文本参数
System.out.println("---" + fp);
// fp.setContentType(MIME.getMIME(file.getName().substring(file.getName().lastIndexOf(".")+1)));
//StringPart:普通的文本参数
StringPart uname=new StringPart("gShopID", DangDangConstant.gShopID+"");
StringPart pass=new StringPart("validateString", md5String); Part[] parts = {uname,pass,fp};
//对于MIME类型的请求,httpclient建议全用MulitPartRequestEntity进行包装
MultipartRequestEntity mre=new MultipartRequestEntity(parts,post.getParams());
post.setRequestEntity(mre);
HttpClient httpclient = new HttpClient();
// 由于要上传的文件可能比较大 , 因此在此设置最大的连接超时时间
httpclient.getHttpConnectionManager(). getParams().setConnectionTimeout(5000);
int result = httpclient.executeMethod(post);
System.out.println( "Response status code: " + result);
System.out.println( "Response body: " );
System.out.println(post.getResponseBodyAsString());
post.releaseConnection();
}catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
}哪位高手以前开发过的 帮帮忙哦
StringBuffer url = new StringBuffer();
url.append("http://api.dangdang.com/v2/sendGoods.php");
url.append("?gShopID="+DangDangConstant.gShopID);
PostMethod post = new PostMethod(url.toString());
//post.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
post.setRequestHeader( "Content-type" , "text/xml; charset=GBK" );
post.setRequestHeader("Accept-Language","zh-cn");
post.setRequestHeader("Connection","Keep-Alive");
try {
// 生成validateString 验证码
StringBuffer rev = new StringBuffer();
rev.append(DangDangConstant.gShopID);
rev.append(DangDangConstant.key);
String md5String = Md5Util.makeMd5Sum(ChangeToGBK.toGBK(rev.toString()).getBytes());
File file = new File(dir);
if (!file.exists()) {
return false;
}
// FilePart:用来上传文件的类
FilePart fp = new FilePart("sendGoods", file); //Part:类专门用来上传文件,其子类 ,FilePart:用来上传文件的类 StringPart:普通的文本参数
System.out.println("---" + fp);
// fp.setContentType(MIME.getMIME(file.getName().substring(file.getName().lastIndexOf(".")+1)));
//StringPart:普通的文本参数
StringPart uname=new StringPart("gShopID", DangDangConstant.gShopID+"");
StringPart pass=new StringPart("validateString", md5String); Part[] parts = {uname,pass,fp};
//对于MIME类型的请求,httpclient建议全用MulitPartRequestEntity进行包装
MultipartRequestEntity mre=new MultipartRequestEntity(parts,post.getParams());
post.setRequestEntity(mre);
HttpClient httpclient = new HttpClient();
// 由于要上传的文件可能比较大 , 因此在此设置最大的连接超时时间
httpclient.getHttpConnectionManager(). getParams().setConnectionTimeout(5000);
int result = httpclient.executeMethod(post);
System.out.println( "Response status code: " + result);
System.out.println( "Response body: " );
System.out.println(post.getResponseBodyAsString());
post.releaseConnection();
}catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
}哪位高手以前开发过的 帮帮忙哦
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货