1.å¦ä½ä½¿ç¨HttpClient
å¦ä½ä½¿ç¨HttpClient
ä¸ãç®ä»
HttpClientæ¯Apache Jakarta Commonä¸çå项ç®ï¼ç¨æ¥æä¾é«æçãææ°çãåè½ä¸°å¯çæ¯æHTTPåè®®ç客æ·ç«¯ç¼ç¨å·¥å ·å ï¼å¹¶ä¸å®æ¯æHTTPåè®®ææ°ççæ¬å建议ãHttpClientå·²ç»åºç¨å¨å¾å¤ç项ç®ä¸ï¼æ¯å¦Apache Jakartaä¸å¾èåçå¦å¤ä¸¤ä¸ªå¼æºé¡¹ç®CactusåHTMLUnité½ä½¿ç¨äºHttpClientã
äºãç¹æ§
1. åºäºæ åã纯åçjavaè¯è¨ãå®ç°äºHttp1.0åHttp1.1
2. 以å¯æ©å±çé¢å对象çç»æå®ç°äºHttpå ¨é¨çæ¹æ³ï¼GET,-1.5的源码 POST, PUT, DELETE, HEAD, OPTIONS, and TRACEï¼ã
3. æ¯æHTTPSåè®®ã
4. éè¿Http代ç建ç«éæçè¿æ¥ã
5. å©ç¨CONNECTæ¹æ³éè¿Http代ç建ç«é§éç.test;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.util.ArrayList;
import java.util.List;
import javax.net.ssl.SSLContext;
import org.apache.ment = new StringBody("A binary file of some kind", ContentType.TEXT_PLAIN);
HttpEntity reqEntity = MultipartEntityBuilder.create().addPart("bin", bin).addPart("comment", comment).build();
httppost.setEntity(reqEntity);
System.out.println("executing request " + httppost.getRequestLine());
CloseableHttpResponse response = httpclient.execute(httppost);
try {
System.out.println("----------------------------------------");
System.out.println(response.getStatusLine());
HttpEntity resEntity = response.getEntity();
if (resEntity != null) {
System.out.println("Response content length: " + resEntity.getContentLength());
}
EntityUtils.consume(resEntity);
} finally {
response.close();
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
httpclient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}</namevaluepair></namevaluepair></namevaluepair></namevaluepair>
2024-11-19 09:271832人浏览
2024-11-19 08:39293人浏览
2024-11-19 07:392608人浏览
2024-11-19 07:242477人浏览
2024-11-19 06:54112人浏览
2024-11-19 06:451218人浏览
1.嵌入式Linux之uboot源码make配置编译正向分析(一)2.bootLinux Kernel 镜像的生成以及加载3.剖析Linux内核源码解读之《配置与编译》嵌入式Linux之uboot源码
1.?ͻ?ָ?깫ʽԴ???ͻ?ָ?깫ʽԴ?? 1) æ æé´åç°è¯¥å¸ï¼è¿4个æäºä¹ä¸ç¥è§£å³äºåï¼ï¼ 2ï¼ä
1.网贷源代码什么意思2.企业易支付系统+手机端,第三方多通道支付源码3.云HIS医院管理系统源码,SaaS模式+Java云HIS系统融合B/S版开箱即用4.银行来源码是什么意思5.什么是期货源代码网