路过的大神帮忙看看HttpURLConnection异常
本帖最后由 u010022574 于 2013-09-13 22:13:28 编辑
最近要在公司系统上做一个连接第三方接口进行身份证验证的功能 于是写了下面一个类
首先说明的是能验证成功 但是偶尔会发生405 not allowed 或者
连接失败,数据接受错误 大神们看看有什么不合理的地方 为什么会发生405和连接失败呢???
package tangdi.util.pos;
import java.io.BufferedReader;
import java.io.FileOutputStream;
import
java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import
java.net.MalformedURLException;
import java.net.URL;
import java.text.MessageFormat;
import javax.inject.Named;
import net.sf.json.JSONObject;
import org.apache.commons.httpclient.HttpClient;
import sun.misc.BASE64Decoder;
import tangdi.engine.context.Etf;
import tangdi.engine.context.Log;
public class identity
{
public static final int RESPCODE_SUCCESS = 200;
@Named("IdentityValidator")
public static void IdentityValidator(@Named("chlCd") String chlCd, @Named("MAC") String MAC, @Named("TrDt") String TrDt, @Named("cardNo") String cardNo, @Named("cardName") String cardName)
{
String url = "http://user.icardpay.com/hk-frt-sys-web/F10041.front?chlcd=" +
chlCd +
"&MAC=" +
MAC +
"&TrDt=" +
TrDt +
"&cardNo=" +
cardNo +
"&cardName=" + cardName;
HttpClient client = new HttpClient();
client.getHttpConnectionManager().getParams().setConnectionTimeout(
60000);
client.getHttpConnectionManager().getParams().setSoTimeout(60000);
String message = "";
HttpURLConnection urlCon = openConnection(url);
System.out.println(urlCon);
try {
urlCon.setRequestMethod("POST");
Log.info("message:urlCon.setRequestMethod(POST);", new Object[0]);
urlCon.setDoOutput(true);