纯搬运:http://blog.csdn.net/sunny243788557/article/details/7903690
第一种方法,适用于httpclient4.0.3 里边有get和post两种方法供你发送请求使用。导入证书发送请求的在这里就不说了,网上到处都是
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.Socket; import java.net.SocketAddress; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.net.URLConnection; import java.net.URLEncoder; import java.net.UnknownHostException; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import javax.net.SocketFactory; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSession; import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.conn.ClientConnectionManager; import org.apache.http.conn.ConnectTimeoutException; import org.apache.http.conn.scheme.HostNameResolver; 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.entity.StringEntity; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.params.HttpConnectionParams; import org.apache.http.protocol.HTTP; import org.apache.http.util.EntityUtils; /* * author:haungxuebin * 云南新接口 * */ public class HttpClientSendPost { private static DefaultHttpClient client; /** * 访问https的网站 * @param httpclient */ private static void enableSSL(DefaultHttpClient httpclient){ //调用ssl try { SSLContext sslcontext = SSLContext.getInstance("TLS"); sslcontext.init(null, new TrustManager[] { truseAllManager }, null); SSLSocketFactory sf = new SSLSocketFactory(sslcontext); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); Scheme https = new Scheme("https", sf, 443); httpclient.getConnectionManager().getSchemeRegistry().register(https); } catch (Exception e) { e.printStackTrace(); } } /** * 重写验证方法,取消检测ssl */ private static TrustManager truseAllManager = new X509TrustManager(){ public void checkClientTrusted( java.security.cert.X509Certificate[] arg0, String arg1) throws CertificateException { // TODO Auto-generated method stub } public void checkServerTrusted( java.security.cert.X509Certificate[] arg0, String arg1) throws CertificateException { // TODO Auto-generated method stub } public java.security.cert.X509Certificate[] getAcceptedIssuers() { // TODO Auto-generated method stub return null; } }; /** * HTTP Client Object,used HttpClient Class before(version 3.x),but now the * HttpClient is an interface */ public static String sendXMLDataByGet(String url,String xml){ // 创建HttpClient实例 if (client == null) { // Create HttpClient Object client = new DefaultHttpClient(); enableSSL(client); } StringBuilder urlString=new StringBuilder(); urlString.append(url); urlString.append("?"); System.out.println("getUTF8XMLString(xml):"+getUTF8XMLString(xml)); try { urlString.append(URLEncoder.encode( getUTF8XMLString(xml) , "UTF-8" )); } catch (UnsupportedEncodingException e2) { // TODO Auto-generated catch block e2.printStackTrace(); } String urlReq=urlString.toString(); // 创建Get方法实例 HttpGet httpsgets = new HttpGet(urlReq); String strRep=""; try { HttpResponse response = client.execute(httpsgets); HttpEntity entity = response.getEntity(); if (entity != null) { strRep = EntityUtils.toString(response.getEntity()); // Do not need the rest httpsgets.abort(); } } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return strRep; } /** * Send a XML-Formed string to HTTP Server by post method * * @param url * the request URL string * @param xmlData * XML-Formed string ,will not check whether this string is * XML-Formed or not * @return the HTTP response status code ,like 200 represents OK,404 not * found * @throws IOException * @throws ClientProtocolException */ public static String sendXMLDataByPost(String url, String xmlData) throws ClientProtocolException, IOException { if (client == null) { // Create HttpClient Object client = new DefaultHttpClient(); enableSSL(client); } client.getParams().setParameter("http.protocol.content-charset", HTTP.UTF_8); client.getParams().setParameter(HTTP.CONTENT_ENCODING, HTTP.UTF_8); client.getParams().setParameter(HTTP.CHARSET_PARAM, HTTP.UTF_8); client.getParams().setParameter(HTTP.DEFAULT_PROTOCOL_CHARSET, HTTP.UTF_8); // System.out.println(HTTP.UTF_8); // Send data by post method in HTTP protocol,use HttpPost instead of // PostMethod which was occurred in former version // System.out.println(url); HttpPost post = new HttpPost(url); post.getParams().setParameter("http.protocol.content-charset", HTTP.UTF_8); post.getParams().setParameter(HTTP.CONTENT_ENCODING, HTTP.UTF_8); post.getParams().setParameter(HTTP.CHARSET_PARAM, HTTP.UTF_8); post.getParams() .setParameter(HTTP.DEFAULT_PROTOCOL_CHARSET, HTTP.UTF_8); // Construct a string entity StringEntity entity = new StringEntity(getUTF8XMLString(xmlData), "UTF-8"); entity.setContentType("text/xml;charset=UTF-8"); entity.setContentEncoding("UTF-8"); // Set XML entity post.setEntity(entity); // Set content type of request header post.setHeader("Content-Type", "text/xml;charset=UTF-8"); // Execute request and get the response HttpResponse response = client.execute(post); HttpEntity entityRep = response.getEntity(); String strrep=""; if (entityRep != null) { strrep = EntityUtils.toString(response.getEntity()); // Do not need the rest post.abort(); } // Response Header - StatusLine - status code // statusCode = response.getStatusLine().getStatusCode(); return strrep; } /** * Get XML String of utf-8 * * @return XML-Formed string */ public static String getUTF8XMLString(String xml) { // A StringBuffer Object StringBuffer sb = new StringBuffer(); sb.append(xml); String xmString = ""; try { xmString = new String(sb.toString().getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } // return to String Formed return xmString.toString(); } }
第二种仿http的不用HttpClient 都是jdk自带的包
package org.sp.sc.util; import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.net.URL; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSession; import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; /** * 无视Https证书是否正确的Java Http Client * * * @author huangxuebin * * @create 2012.8.17 * @version 1.0 */ public class HttpsUtil { /** * 忽视证书HostName */ private static HostnameVerifier ignoreHostnameVerifier = new HostnameVerifier() { public boolean verify(String s, SSLSession sslsession) { System.out.println("WARNING: Hostname is not matched for cert."); return true; } }; /** * Ignore Certification */ private static TrustManager ignoreCertificationTrustManger = new X509TrustManager() { private X509Certificate[] certificates; @Override public void checkClientTrusted(X509Certificate certificates[], String authType) throws CertificateException { if (this.certificates == null) { this.certificates = certificates; System.out.println("init at checkClientTrusted"); } } @Override public void checkServerTrusted(X509Certificate[] ax509certificate, String s) throws CertificateException { if (this.certificates == null) { this.certificates = ax509certificate; System.out.println("init at checkServerTrusted"); } // for (int c = 0; c < certificates.length; c++) { // X509Certificate cert = certificates[c]; // System.out.println(" Server certificate " + (c + 1) + ":"); // System.out.println(" Subject DN: " + cert.getSubjectDN()); // System.out.println(" Signature Algorithm: " // + cert.getSigAlgName()); // System.out.println(" Valid from: " + cert.getNotBefore()); // System.out.println(" Valid until: " + cert.getNotAfter()); // System.out.println(" Issuer: " + cert.getIssuerDN()); // } } @Override public X509Certificate[] getAcceptedIssuers() { // TODO Auto-generated method stub return null; } }; public static String getMethod(String urlString) { ByteArrayOutputStream buffer = new ByteArrayOutputStream(512); try { URL url = new URL(urlString); /* * use ignore host name verifier */ HttpsURLConnection.setDefaultHostnameVerifier(ignoreHostnameVerifier); HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); // Prepare SSL Context TrustManager[] tm = { ignoreCertificationTrustManger }; SSLContext sslContext = SSLContext.getInstance("SSL", "SunJSSE"); sslContext.init(null, tm, new java.security.SecureRandom()); // 从上述SSLContext对象中得到SSLSocketFactory对象 SSLSocketFactory ssf = sslContext.getSocketFactory(); connection.setSSLSocketFactory(ssf); InputStream reader = connection.getInputStream(); byte[] bytes = new byte[512]; int length = reader.read(bytes); do { buffer.write(bytes, 0, length); length = reader.read(bytes); } while (length > 0); // result.setResponseData(bytes); System.out.println(buffer.toString()); reader.close(); connection.disconnect(); } catch (Exception ex) { ex.printStackTrace(); } finally { } String repString= new String (buffer.toByteArray()); return repString; } // public static void main(String[] args) { // String urlString = "https://218.202.0.241:8081/XMLReceiver"; // String output = new String(HttpsUtil.getMethod(urlString)); // System.out.println(output); // } }
相关推荐
"气瓶搬运、装卸、储存和使用安全规定" 《气瓶搬运、装卸、储存和使用安全规定》GBT 34525-2017参照.docx是中华人民共和国国家标准,规定了生产、经营、储存及以上场所使用区域内瓶装气体气瓶的搬运、装卸、储存和...
《装卸搬运工安全作业规程详解》 装卸搬运工作在物流行业中占据着至关重要的地位,而安全作业规程则是保障员工生命安全和财产不受损害的关键。本文将深入解析《装卸搬运工安全作业规程精选》中的各项要点,旨在提升...
机械搬运吊装安全培训材料.pptx
搬运工安全操作规程正式样本.pdf
TCP跟踪功能则用于验证搬运路径的准确性,保证整个搬运过程的流畅性。 搬运工具设计选用了气动吸盘,因其反应迅速、安全可靠且能耗低。吸盘通过真空设备抽吸形成负气压来吸附货物,然后在指定位置充气释放,适应了...
【标题】:“2021年面板搬运系统行业生产安全事故应急预案” 【描述】:文档旨在为面板搬运系统行业提供一套全面的应急预案,以应对可能发生的生产安全事故,保护人员安全和行业运营。 【标签】:“安全生产”、...
它能够高效、安全地搬运大型综采支架设备,大大减轻了劳动强度,并提升了作业效率。国内在支架搬运车的研制和应用方面取得了一定进展,但与国际先进水平相比还存在差距。国内支架搬运车的发展起步较晚,但近年来进步...
搬运机器人设计 搬运机器人是一种能够模仿人手部的部分动作的机器人,按照设定的程序、轨迹与要求,代替人工在高温与危险的作业区进行单调持久的作业。该机器人能够使人手避免出现可能的危险情况,保障生产安全,还...
这一步骤对于验证搬运机器人的可靠性和安全性非常重要。 大负载四轴搬运机器人实验平台的结构设计与分析是解决高速重载机器人在汽车、冶金、物流等行业中的广泛应用中遇到的挑战的关键一步骤。该平台的设计主要涉及...
多多视频带货,纯搬运搞佣金,小白也能操作【揭秘】
6. **人机协作**:随着技术的发展,ABB也推出了适合与人类工作者并肩作业的协作机器人(Cobots),它们在搬运纸箱时能感知周围环境,自动调整速度以确保安全。 7. **效率优化**:通过合理的程序设计和工作流程优化...
本研究旨在提出并验证一种搬运机械手的设计方案,以提升工作效率,降低劳动强度,并确保作业安全性。 首先,设计的机械手主要由加持机构和运动机构两部分构成。加持机构能够适应不同形状、尺寸、重量和材质的物体,...
过快的速度可能导致精度下降,过大的加速度可能影响机器人的寿命。 5. **I/O控制**: 通过编程控制输入/输出信号,机器人可以与其他设备(如传感器、PLC)进行通信,实现同步操作和安全监控。 6. **程序结构**: ...
工业搬运与安全培训课件是关注在工作环境中正确搬运物品以防止工伤事故的重要主题。尤其在工业领域,不注意搬运安全可能导致员工手腕、背部、脚部和腿部受伤,甚至引起永久性的背部伤害,严重影响员工的生活和职业...
针对智能制造对于搬运机器人的大量需求,开发了基于MOTOMAN-UP6六自由度通用机械臂的搬运机器人,并对机器人的控制方法进行研究。独立开发了双输出轴蜗轮蜗杆...搬运箱体的实验验证了搬运机器人系统及控制方法的可行性。
6. **实验验证和性能评估**:通过实验验证了所设计的纱筒搬运机器人的有效性,结果显示该机器人能够安全、稳定地完成对两只筒纱的搬运工作循环。这验证了设计的机器人满足实际的生产需求。 7. **文献标识和分类**:...
本安全管理规定旨在确保电动托盘搬运车工的安全作业,防止意外事故的发生。 2.1 检查与维护:在每日开始工作前,操作员必须对电动托盘搬运车进行全面检查,包括所有安全开关和设备。这不仅涉及到制动系统、灯光信号...
- **安全性**:传统搬运车通常使用红外线传感器检测障碍物,容易受到环境因素干扰;智能AGV则采用先进的自动避障系统,能更准确地测量障碍物距离,确保运行安全。 - **灵活性**:传统搬运车的站点布局受限较大;智能...
为提高煤矿液压支架搬运效率,降低搬运成本,分析了我国目前支架...实际应用表明,研究提出的搬运方式使用设备单一,转运环节简单,参与人数较少,可避免安全隐患,提高支架搬运效率,缩短综采工作面的搬家倒面周期。
【文档标题】:“材料二次搬运专项方案整理.docx” ...这个方案详尽地阐述了从材料的接收、存储到搬运到施工现场的全过程,确保了施工过程中的物流管理和作业安全,体现了项目管理的严谨性和专业性。