本文整理匯總了Java中org.apache.http.client.ClientProtocolException.printStackTrace方法的典型用法代碼示例。如果您正苦於以下問題:Java ClientProtocolException.printStackTrace方法的具體用法?Java ClientProtocolException.printStackTrace怎麽用?Java ClientProtocolException.printStackTrace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.http.client.ClientProtocolException
的用法示例。
在下文中一共展示了ClientProtocolException.printStackTrace方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: PostConnect
import org.apache.http.client.ClientProtocolException; //導入方法依賴的package包/類
public String PostConnect(String httpUrl, String str) {
String resultData = "";
HttpPost httpPost = new HttpPost(httpUrl);
List<NameValuePair> params = new ArrayList();
params.add(new BasicNameValuePair("data", str));
try {
httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
HttpResponse httpResponse = new DefaultHttpClient().execute(httpPost);
if (httpResponse.getStatusLine().getStatusCode() == 200) {
resultData = EntityUtils.toString(httpResponse.getEntity());
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e2) {
e2.printStackTrace();
} catch (IOException e3) {
e3.printStackTrace();
}
return resultData;
}
示例2: printStackTrace
import org.apache.http.client.ClientProtocolException; //導入方法依賴的package包/類
public static void printStackTrace(String TAG, ClientProtocolException e) {
if (IsDebug) {
e.printStackTrace();
} else {
logException(TAG, e);
}
}
示例3: res
import org.apache.http.client.ClientProtocolException; //導入方法依賴的package包/類
private String res(HttpRequestBase method) {
HttpClientContext context = HttpClientContext.create();
CloseableHttpResponse response = null;
String content = RESPONSE_CONTENT;
try {
response = client.execute(method, context);//執行GET/POST請求
HttpEntity entity = response.getEntity();//獲取響應實體
if(entity!=null) {
Charset charset = ContentType.getOrDefault(entity).getCharset();
content = EntityUtils.toString(entity, charset);
EntityUtils.consume(entity);
}
} catch(ConnectTimeoutException cte) {
LOG.error("請求連接超時,由於 " + cte.getLocalizedMessage());
cte.printStackTrace();
} catch(SocketTimeoutException ste) {
LOG.error("請求通信超時,由於 " + ste.getLocalizedMessage());
ste.printStackTrace();
} catch(ClientProtocolException cpe) {
LOG.error("協議錯誤(比如構造HttpGet對象時傳入協議不對(將'http'寫成'htp')or響應內容不符合),由於 " + cpe.getLocalizedMessage());
cpe.printStackTrace();
} catch(IOException ie) {
LOG.error("實體轉換異常或者網絡異常, 由於 " + ie.getLocalizedMessage());
ie.printStackTrace();
} finally {
try {
if(response!=null) {
response.close();
}
} catch(IOException e) {
LOG.error("響應關閉異常, 由於 " + e.getLocalizedMessage());
}
if(method!=null) {
method.releaseConnection();
}
}
return content;
}
示例4: getHtml
import org.apache.http.client.ClientProtocolException; //導入方法依賴的package包/類
/**
* 對上一個方法的重載,使用本機ip進行網站爬取
*/
public static String getHtml(String url) throws ClassNotFoundException,
IOException {
String entity = null;
CloseableHttpClient httpClient = HttpClients.createDefault();
//設置超時處理
RequestConfig config = RequestConfig.custom().setConnectTimeout(5000).
setSocketTimeout(5000).build();
HttpGet httpGet = new HttpGet(url);
httpGet.setConfig(config);
httpGet.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;" +
"q=0.9,image/webp,*/*;q=0.8");
httpGet.setHeader("Accept-Encoding", "gzip, deflate, sdch");
httpGet.setHeader("Accept-Language", "zh-CN,zh;q=0.8");
httpGet.setHeader("Cache-Control", "no-cache");
httpGet.setHeader("Connection", "keep-alive");
httpGet.setHeader("Cookie", "_free_proxy_session=BAh7B0kiD3Nlc3Npb25faWQGOgZFVEkiJTRkYjMyM" +
"TU3NGRjMWVhM2JlMDA5Y2IyNzZlZmVlZTYwBjsAVEkiEF9jc3JmX3Rva2VuBjsARkkiMUhtT0pjcnRT" +
"bm9CZEllSXNTYkNZZWk2Nnp3NGNDcFFSQVFodzk1dmpLZWM9BjsARg%3D%3D--09d8736fbfb9a8544" +
"b46eef48bb320c2b40ee721; Hm_lvt_0cf76c77469e965d2957f0553e6ecf59=1492128157,149" +
"2160558,1492347839,1492764281; Hm_lpvt_0cf76c77469e965d2957f0553e6ecf59=1492764295");
httpGet.setHeader("Host", "www.xicidaili.com");
httpGet.setHeader("Pragma", "no-cache");
httpGet.setHeader("Upgrade-Insecure-Requests", "1");
httpGet.setHeader("User-Agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 " +
"(KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36");
try {
//客戶端執行httpGet方法,返回響應
CloseableHttpResponse httpResponse = httpClient.execute(httpGet);
//得到服務響應狀態碼
if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
entity = EntityUtils.toString(httpResponse.getEntity(), "utf-8");
}
httpResponse.close();
httpClient.close();
} catch (ClientProtocolException e) {
e.printStackTrace();
}
return entity;
}
示例5: getHtml1
import org.apache.http.client.ClientProtocolException; //導入方法依賴的package包/類
/**
* 對上一個方法的重載,使用本機ip進行網站爬取
*/
public static String getHtml1(String url) throws ClassNotFoundException,
IOException {
String entity = null;
CloseableHttpClient httpClient = HttpClients.createDefault();
//設置超時處理
RequestConfig config = RequestConfig.custom().setConnectTimeout(5000).
setSocketTimeout(5000).build();
HttpGet httpGet = new HttpGet(url);
httpGet.setConfig(config);
httpGet.setHeader("Accept", "*/*");
httpGet.setHeader("Accept-Encoding", "gzip, deflate, sdch");
httpGet.setHeader("Content-Type", " text/plain;charset=utf-8");
httpGet.setHeader("Accept-Language", "zh-CN,zh;q=0.8");
httpGet.setHeader("User-Agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 " +
"(KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36");
try {
//客戶端執行httpGet方法,返回響應
CloseableHttpResponse httpResponse = httpClient.execute(httpGet);
//得到服務響應狀態碼
if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
entity = EntityUtils.toString(httpResponse.getEntity(), "utf-8");
}
httpResponse.close();
httpClient.close();
} catch (ClientProtocolException e) {
e.printStackTrace();
}
return entity;
}
示例6: SendContact
import org.apache.http.client.ClientProtocolException; //導入方法依賴的package包/類
private void SendContact(String encContact, String encIMEI)
{
try
{
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpPost = new HttpGet(constant.GET_LAST_UPDATE + "/" + encContact + "/" + encIMEI + "/");
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity entity = httpResponse.getEntity();
// String s = IOUtils.toString(entity.getContent(), "utf-8");
// JSONObject json = null;
// try {
// json = new JSONObject(s);
// } catch (JSONException e) {
// e.printStackTrace();
// }
}
catch (UnsupportedEncodingException e1)
{
FirebaseCrash.report(e1);
e1.printStackTrace();
}
catch (ClientProtocolException e2)
{
FirebaseCrash.report(e2);
Log.e("ClientProtocolException", e2.toString());
e2.printStackTrace();
}
catch (IllegalStateException e3)
{
FirebaseCrash.report(e3);
Log.e("IllegalStateException", e3.toString());
e3.printStackTrace();
}
catch (IOException e4)
{
FirebaseCrash.report(e4);
Log.e("IOException", e4.toString());
e4.printStackTrace();
}
}