java httpclient 图片上传,httpclient post上传图片的有关问题

httpclient post上传图片的问题。

本帖最后由 cnicc 于 2014-03-21 01:35:43 编辑

这个是要post到的接口,https://www.peuland.com/captcha/captchaimg.php

主要功能是将本地验证码图片上传到这个接口,通过其来识别验证码。

表单有用户名user,密码pwd,验证码类型type ,图片img

全部代码如下,执行post提交后,返回结果总是提示 user error。基本可以确定用户密码没错。

百度了下,发现这位同学也有这个问题,不过他是用C#,问题也没解决。

传送门,http://bbs.csdn.net/topics/390606480

怀疑是代码逻辑上有问题。

package com.test;

import java.io.BufferedReader;

import java.io.File;

import java.io.IOException;

import java.io.InputStream;

import java.io.InputStreamReader;

import java.util.ArrayList;

import java.util.List;

import javax.net.ssl.SSLContext;

import javax.net.ssl.TrustManager;

import javax.net.ssl.X509TrustManager;

import javax.security.cert.CertificateException;

import javax.security.cert.X509Certificate;

import org.apache.http.HttpEntity;

import org.apache.http.HttpResponse;

import org.apache.http.client.ClientProtocolException;

import org.apache.http.client.methods.HttpPost;

import org.apache.http.conn.scheme.Scheme;

import org.apache.http.conn.scheme.SchemeRegistry;

import org.apache.http.conn.ssl.SSLSocketFactory;

import org.apache.http.impl.client.DefaultHttpClient;

import org.apache.http.util.EntityUtils;

import org.apache.http.NameValuePair;

import org.apache.http.client.entity.UrlEncodedFormEntity;

import org.apache.http.message.BasicNameValuePair;

import org.apache.http.entity.FileEntity;

import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;

public class lyg01vote {

/**

* @param args

* @throws IOException

* @throws ClientProtocolException

*/

public static class WebClientDevWrapper {

public static org.apache.http.client.HttpClient wrapClient(org.apache.http.client.HttpClient base) {

try {

SSLContext ctx = SSLContext.getInstance("TLS");

X509TrustManager tm = new X509TrustManager() {

public java.security.cert.X509Certificate[] getAcceptedIssuers() {

return null;

}

public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {}

public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {}

public void checkClientTrusted(

java.security.cert.X509Certificate[] chain,

String authType)

throws java.security.cert.CertificateException {

// TODO Auto-generated method stub

}

public void checkServerTrusted(

java.security.cert.X509Certificate[] chain,

String authType)

throws java.security.cert.CertificateException {

// TODO Auto-generated method stub

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值