å¦ä½ä½¿ç¨HttpClient
ä¸ãç®ä»
HttpClientæ¯Apache Jakarta Commonä¸çå项ç®ï¼ç¨æ¥æä¾é«æçãææ°çãåè½ä¸°å¯çæ¯æHTTPåè®®ç客æ·ç«¯ç¼ç¨å·¥å ·å ï¼å¹¶ä¸å®æ¯æHTTPåè®®ææ°ççæ¬å建议ãHttpClientå·²ç»åºç¨å¨å¾å¤ç项ç®ä¸ï¼æ¯å¦Apache Jakartaä¸å¾èåçå¦å¤ä¸¤ä¸ªå¼æºé¡¹ç®CactusåHTMLUnité½ä½¿ç¨äºHttpClientã
äºãç¹æ§
1. åºäºæ åã纯åçjavaè¯è¨ãå®ç°äºHttp1.0åHttp1.1
2. 以å¯æ©å±çé¢å对象çç»æå®ç°äºHttpå ¨é¨çæ¹æ³ï¼GET,源码cci源码有箭头指标 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();
ponentsseparatedbystring:@]];
if(murlarray.count=2){
[mUrlArrayremoveLastObject]ï¼
}
//urlResurltæ¯ææè·åå¾ççURLçæ¼æ¥ï¼MUrlArrayæ¯ææURLçæ°ç»ã
//ç¹å»jsæ·»å å¾ç
[mWebViewstringbyevaluatingjavascriptfromstring:@å½æ°registimageclickaction(){
varimgs=document.getElementsByTagName(img);varimgs=document.getelementsbytagname(img
varlength=imgs.length;varlength=imgs.length
for(varI=0ï¼æi){
img=imgs[I]ï¼
img.onclick=function(){
window.location.href=å¾åé¢è§:this.src}
}
}
[mWebViewstringbyevaluatingjavascriptfromstring:@registimageclickaction()ï¼
}
//å¨è¿ä¸ªæ¹æ³ä¸ï¼æè·å¾åçç¹å»äºä»¶å被ç¹å»å¾åçurlã
-(BOOL)webView:(UIWebView*)webViewshouldStartLoadWithRequest:(NSURLRequest*)请æ±å¯¼èªç±»å:(UIWebViewNavigationType)导èªç±»å{
//é¢è§å¾ç
å¦æ(ã请æ±ãURL.schemeisequaltostring:@å¾åé¢è§å¾åé¢è§:
path=[pathstringbyaddingpercentescapesusingcoding:nsuTF8stringencoding]ï¼
//pathæ¯è¢«ç¹å»å¾åçurlã
è¿åå¦ï¼
}
è¿åYES
}
åªäºæ¹æ³å¯ä»¥è·å/s?wd=WebDriver&ie=utf-8";
try {
HttpURLConnection httpUrlConnection = (HttpURLConnection) new URL(url).openConnection();
httpUrlConnection.setRequestMethod("GET");
httpUrlConnection.setUseCaches(true); //使用缓存
httpUrlConnection.connect(); //建立连接
InputStream inputStream = httpUrlConnection.getInputStream(); //读取输入流
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
String string;
while ((string = bufferedReader.readLine()) != null) {
System.out.println(string); //打印输出
}
bufferedReader.close();
inputStream.close();
httpUrlConnection.disconnect();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} //创建连接
}
}
2024-11-20 15:30
2024-11-20 15:26
2024-11-20 14:54
2024-11-20 14:43
2024-11-20 14:11