本文整理匯總了Java中org.apache.http.client.HttpResponseException.getMessage方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpResponseException.getMessage方法的具體用法?Java HttpResponseException.getMessage怎麽用?Java HttpResponseException.getMessage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.http.client.HttpResponseException
的用法示例。
在下文中一共展示了HttpResponseException.getMessage方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: uploadFile
import org.apache.http.client.HttpResponseException; //導入方法依賴的package包/類
public WebResponse uploadFile(String path, String fname, InputStream in,
String stoken) throws ClientProtocolException, IOException {
HttpPost post = new HttpPost(path);
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
StringBody fn = new StringBody(fname, ContentType.MULTIPART_FORM_DATA);
builder.addPart("fname", fn);
builder.addBinaryBody("file", in, ContentType.APPLICATION_XML, fname);
BasicCookieStore cookieStore = new BasicCookieStore();
if (stoken != null) {
BasicClientCookie cookie = new BasicClientCookie(
Constants.SECURE_TOKEN_NAME, stoken);
cookie.setDomain(TestConstants.JETTY_HOST);
cookie.setPath("/");
cookieStore.addCookie(cookie);
}
TestConstants.LOG.debug("stoken=" + stoken);
HttpClient client = HttpClientBuilder.create().
setDefaultCookieStore(cookieStore).build();
HttpEntity entity = builder.build();
post.setEntity(entity);
HttpResponse response = client.execute(post);
String body;
ResponseHandler<String> handler = new BasicResponseHandler();
try {
body = handler.handleResponse(response);
} catch (HttpResponseException e) {
return new WebResponse(e.getStatusCode(), e.getMessage());
}
return new WebResponse(response.getStatusLine().getStatusCode(), body);
}
示例2: ModelResponseException
import org.apache.http.client.HttpResponseException; //導入方法依賴的package包/類
public ModelResponseException(Throwable paramThrowable)
{
if ((paramThrowable instanceof HttpResponseException))
{
HttpResponseException localHttpResponseException = (HttpResponseException)paramThrowable;
if (localHttpResponseException.getStatusCode() == 404){
statusCode = STATUS_CODE_NETWORK_404;
}else{
statusCode = localHttpResponseException.getStatusCode();
}
msg = localHttpResponseException.getMessage();
}
if ((paramThrowable instanceof ConnectException))
{
statusCode = 983040;
msg = paramThrowable.getMessage();
return;
}
if ((paramThrowable instanceof UnknownHostException))
{
statusCode = 16711680;
msg = paramThrowable.getMessage();
return;
}
if ((paramThrowable instanceof UnknownHostException))
{
statusCode = 16711680;
msg = paramThrowable.getMessage();
return;
}
if (((paramThrowable instanceof SocketTimeoutException)) || ((paramThrowable instanceof ConnectTimeoutException)))
{
statusCode = 268369922;
msg = paramThrowable.getMessage();
return;
}
statusCode = -15;
msg = ("unknown exception:" + paramThrowable.getClass().getName() + " | Message:" + paramThrowable.getMessage());
}