本文整理汇总了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();
}
}