HttpsURLConnection 实现SOAP产生错误

mythos55 2013-02-21 04:42:57
			SSLContext sc = SSLContext.getInstance("SSL"); 
//指定信任https
sc.init(null, new TrustManager[]{new MyX509TrustManager()}, new java.security.SecureRandom());
URL console = new URL(Url+actionString);
HttpsURLConnection httpsConn = (HttpsURLConnection) console.openConnection();

//HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
httpsConn.setSSLSocketFactory(sc.getSocketFactory());

//http = (HttpsURLConnection) console.openConnection();
((HttpsURLConnection) httpsConn).setHostnameVerifier(DO_NOT_VERIFY);
//设置SOAPAction参数
// httpsConn.set
httpsConn.setConnectTimeout(connectionTimeOut);
httpsConn.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
httpsConn.setRequestProperty("charset", "UTF-8");
httpsConn.setRequestProperty("SOAPAction", soapAction + actionString);
httpsConn.setRequestProperty("Host", soapHost);
httpsConn.setRequestProperty("ContentLength", Integer.toString(rqinfo.length));
httpsConn.setReadTimeout(30000);
httpsConn.setRequestMethod("POST");
httpsConn.setDoOutput(true);
httpsConn.setDoInput(true);



java.io.IOException: Server returned HTTP response code: 500 for URL: https://xxxx
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1305)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:234)
怀疑是httpsConn.setRequestProperty("SOAPAction", soapAction + actionString);这里的问题
...全文
402 13 打赏 收藏 举报
写回复
13 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
ganyingshiwo 2013-06-12
你现在可真是大牛了啊
  • 打赏
  • 举报
回复
mythos55 2013-02-26
感谢回答的朋友,虽然没有解决~是哪儿的问题最后也没调查清楚,改用其他方式实现了
  • 打赏
  • 举报
回复
mythos55 2013-02-25
555
  • 打赏
  • 举报
回复
科學信仰 2013-02-22
500说明服务器端已经收到发去的soap消息了,多半已经是业务逻辑层面的问题了,你怀疑的应该没错
  • 打赏
  • 举报
回复
httpsConn.setRequestProperty("SOAPAction", soapAction + actionString);总觉得你这个地方有问题,debug下看下。哪里开始报错的
  • 打赏
  • 举报
回复
mythos55 2013-02-22
引用 3 楼 fangmingshijie 的回复:
Java code?1234567891011121314 httpsConn.setConnectTimeout(connectionTimeOut); httpsConn.setRequestProperty("Content-Type", "text/xml"); httpsConn.setRequestProperty……
		String responseInfo = null;
		BufferedReader input = null;   
		
		byte rqinfo[] = requestInfo.getBytes();
		//设置代理
		//System.setProperty("proxyType", "4");
		System.setProperty("proxyPort", proxyPort);
		System.setProperty("proxyHost", proxyHost);
		System.setProperty("proxySet", proxyFlag);
		logger.info("GreenTreePubInfoaa begin");
		try {  
//			KeyStore ks = KeyStore.getInstance("jks"); 
//            ks.load(new FileInputStream("D:/greentree.cer"), "changeit".toCharArray()); 
//            KeyManagerFactory kmf = KeyManagerFactory.getInstance("sunx509"); 
//            kmf.init(ks, "changeit".toCharArray()); 
            
			SSLContext sc = SSLContext.getInstance("SSL"); 
			//指定信任https
			sc.init(null, new TrustManager[]{new MyX509TrustManager()}, new java.security.SecureRandom());
			URL console = new URL(greenTreeUrl+actionString);
			HttpsURLConnection httpsConn = (HttpsURLConnection) console.openConnection(); 

			//HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());  
			httpsConn.setSSLSocketFactory(sc.getSocketFactory()); 

			//http = (HttpsURLConnection) console.openConnection();  
            ((HttpsURLConnection) httpsConn).setHostnameVerifier(DO_NOT_VERIFY);
            //设置SOAPAction参数
          //  httpsConn.set
            httpsConn.setConnectTimeout(connectionTimeOut);
            httpsConn.setRequestProperty("Content-Type", "text/xml"); 
            httpsConn.setRequestProperty("charset", "UTF-8");
            httpsConn.setRequestProperty("SOAPAction", soapAction + actionString);
            httpsConn.setRequestProperty("Host", soapHost);
            httpsConn.setRequestProperty("ContentLength", Integer.toString(rqinfo.length));
            httpsConn.setReadTimeout(30000);
            httpsConn.setUseCaches (false);//不使用缓存
            httpsConn.setRequestMethod("POST");
            httpsConn.setDoOutput(true);
            httpsConn.setDoInput(true);
            httpsConn.connect() ;
貌似也不行,还是一样的错误,我的还在system里面设置代理了。。也不知道哪儿出了问题
  • 打赏
  • 举报
回复
mythos55 2013-02-22
网上找不到关于HttpsURLConnection设置soap的内容。 是不是我的soap不能这样设置呀
引用 1 楼 dracularking 的回复:
500说明服务器端已经收到发去的soap消息了,多半已经是业务逻辑层面的问题了,你怀疑的应该没错
  • 打赏
  • 举报
回复

 httpsConn.setConnectTimeout(connectionTimeOut);
            httpsConn.setRequestProperty("Content-Type", "text/xml"); 
            httpsConn.setRequestProperty("charset", "UTF-8");
            httpsConn.setRequestProperty("SOAPAction", soapAction + actionString);//确保你这个地方的字符串正确
            httpsConn.setRequestProperty("Host", soapHost);
            httpsConn.setRequestProperty("Content-Length", Integer.toString(rqinfo.length));
            httpsConn.setReadTimeout(30000);
            httpsConn..setUseCaches (false);//不使用缓存
            httpsConn.setRequestMethod("POST");
            httpsConn.setDoOutput(true);
            httpsConn.setDoInput(true);


改为这样试试
  • 打赏
  • 举报
回复
七神之光 2013-02-22
  • 打赏
  • 举报
回复
mythos55 2013-02-22
怎么调么?
引用 9 楼 dracularking 的回复:
引用 7 楼 mythos55 的回复: 在后面报错的 Java code?12345 OutputStream out = httpConn.getOutputStream(); out.write(rqinfo); StringBuffer receivedData = new StringBuffer(); Input……
  • 打赏
  • 举报
回复
科學信仰 2013-02-22
引用 7 楼 mythos55 的回复:
在后面报错的 Java code?12345 OutputStream out = httpConn.getOutputStream(); out.write(rqinfo); StringBuffer receivedData = new StringBuffer(); InputStreamRea……
应该调试服务端
  • 打赏
  • 举报
回复


  InputStreamReader insr = new InputStreamReader(httpsConn
                    .getInputStream());//不要指定编码格式了,你不确定
            int respInt = insr.read();
            while (respInt != -1) {
                System.out.print((char) respInt);
                respInt = insr.read();
            }
  • 打赏
  • 举报
回复
mythos55 2013-02-22
在后面报错的
   OutputStream out = httpConn.getOutputStream();
            out.write(rqinfo);
            StringBuffer receivedData = new StringBuffer();
            InputStreamReader inReader = new InputStreamReader(httpConn
                    .getInputStream(), "UTF-8");//这开始报错

java.io.IOException: Server returned HTTP response code: 500 for URL: https://xxxx
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1305)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:234)
引用 6 楼 fangmingshijie 的回复:
httpsConn.setRequestProperty("SOAPAction", soapAction + actionString);总觉得你这个地方有问题,debug下看下。哪里开始报错的
  • 打赏
  • 举报
回复
发帖
Java EE

6.7w+

社区成员

J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
帖子事件
创建了帖子
2013-02-21 04:42
社区公告
暂无公告