java statusline_Java StatusLine.getReasonPhrase方法代碼示例

本文汇总了Java中org.apache.http.StatusLine.getReasonPhrase方法的典型用法代码示例,共展示了13个代码示例,这些例子默认根据受欢迎程度排序,开发者可通过点赞评价帮助系统推荐更棒的Java代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文整理匯總了Java中org.apache.http.StatusLine.getReasonPhrase方法的典型用法代碼示例。如果您正苦於以下問題:Java StatusLine.getReasonPhrase方法的具體用法?Java StatusLine.getReasonPhrase怎麽用?Java StatusLine.getReasonPhrase使用的例子?那麽恭喜您, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.http.StatusLine的用法示例。

在下文中一共展示了StatusLine.getReasonPhrase方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Java代碼示例。

示例1: doFormatStatusLine

​點讚 3

import org.apache.http.StatusLine; //導入方法依賴的package包/類

/**

* Actually formats a status line.

* Called from {@link #formatStatusLine}.

*

* @param buffer the empty buffer into which to format,

* never null

* @param statline the status line to format, never null

*/

protected void doFormatStatusLine(final CharArrayBuffer buffer,

final StatusLine statline) {

int len = estimateProtocolVersionLen(statline.getProtocolVersion())

+ 1 + 3 + 1; // room for "HTTP/1.1 200 "

final String reason = statline.getReasonPhrase();

if (reason != null) {

len += reason.length();

}

buffer.ensureCapacity(len);

appendProtocolVersion(buffer, statline.getProtocolVersion());

buffer.append(' ');

buffer.append(Integer.toString(statline.getStatusCode()));

buffer.append(' '); // keep whitespace even if reason phrase is empty

if (reason != null) {

buffer.append(reason);

}

}

開發者ID:lamsfoundation,項目名稱:lams,代碼行數:28,

示例2: toFeignResponse

​點讚 3

import org.apache.http.StatusLine; //導入方法依賴的package包/類

Response toFeignResponse(HttpResponse httpResponse) throws IOException {

StatusLine statusLine = httpResponse.getStatusLine();

int statusCode = statusLine.getStatusCode();

String reason = statusLine.getReasonPhrase();

Map> headers = new HashMap>();

for (Header header : httpResponse.getAllHeaders()) {

String name = header.getName();

String value = header.getValue();

Collection headerValues = headers.get(name);

if (headerValues == null) {

headerValues = new ArrayList();

headers.put(name, headerValues);

}

headerValues.add(value);

}

return Response.builder()

.status(statusCode)

.reason(reason)

.headers(headers)

.body(toFeignBody(httpResponse))

.build();

}

開發者ID:wenwu315,項目名稱:XXXX,代碼行數:27,

示例3: doInBackground

​點讚 3

import org.apache.http.StatusLine; //導入方法依賴的package包/類

@Override

protected String doInBackground(String... uri) {

HttpClient httpclient = new DefaultHttpClient();

HttpResponse response;

String responseString = null;

try {

response = httpclient.execute(new HttpGet(uri[0]));

StatusLine statusLine = response.getStatusLine();

if (statusLine.getStatusCode() == 200) {

ByteArrayOutputStream out = new ByteArrayOutputStream();

response.getEntity().writeTo(out);

responseString = out.toString();

out.close();

} else {

// Close the connection.

response.getEntity().getContent().close();

throw new IOException(statusLine.getReasonPhrase());

}

} catch (Exception e) {

return null;

}

return responseString;

}

開發者ID:KoreHuang,項目名稱:WeChatLuckyMoney,代碼行數:24,

示例4: handleResponse

​點讚 2

import org.apache.http.StatusLine; //導入方法依賴的package包/類

private ResponseStream handleResponse(HttpResponse response) throws HttpException, IOException {

if (response == null) {

throw new HttpException("response is null");

}

StatusLine status = response.getStatusLine();

int statusCode = status.getStatusCode();

if (statusCode < 300) {

// Set charset from response header if it's exist.

String responseCharset = OtherUtils.getCharsetFromHttpResponse(response);

charset = TextUtils.isEmpty(responseCharset) ? charset : responseCharset;

return new ResponseStream(response, charset, requestUrl, expiry);

} else if (statusCode == 301 || statusCode == 302) {

if (httpRedirectHandler == null) {

httpRedirectHandler = new DefaultHttpRedirectHandler();

}

HttpRequestBase request = httpRedirectHandler.getDirectRequest(response);

if (request != null) {

return this.sendRequest(request);

}

} else if (statusCode == 416) {

throw new HttpException(statusCode, "maybe the file has downloaded completely");

} else {

throw new HttpException(statusCode, status.getReasonPhrase());

}

return null;

}

開發者ID:SavorGit,項目名稱:Hotspot-master-devp,代碼行數:29,

示例5: assert2xx

​點讚 2

import org.apache.http.StatusLine; //導入方法依賴的package包/類

private static void assert2xx(HttpResponse response)

throws HttpResponseException {

StatusLine statusLine = response.getStatusLine();

if (statusLine.getStatusCode() >= 300) {

String detail = null;

try {

String body = EntityUtils.toString(response.getEntity());

detail = String.format("[%s] %s",

statusLine.getReasonPhrase(), body);

} catch (Exception e) {

detail = statusLine.getReasonPhrase();

}

throw new HttpResponseException(statusLine.getStatusCode(), detail);

}

}

開發者ID:openmicroscopy,項目名稱:omero-ms-queue,代碼行數:16,

示例6: handleResponse

​點讚 2

import org.apache.http.StatusLine; //導入方法依賴的package包/類

@Override

public InputStream handleResponse(final HttpResponse response) throws IOException {

final StatusLine statusLine = response.getStatusLine();

final HttpEntity entity = response.getEntity();

if (statusLine.getStatusCode() >= 300) {

EntityUtils.consume(entity);

throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase());

}

return entity == null ? null : entity.getContent();

}

開發者ID:11590692,項目名稱:Wechat-Group,代碼行數:11,

示例7: handleResponse

​點讚 2

import org.apache.http.StatusLine; //導入方法依賴的package包/類

@Override

public String handleResponse(final HttpResponse response) throws IOException {

final StatusLine statusLine = response.getStatusLine();

final HttpEntity entity = response.getEntity();

if (statusLine.getStatusCode() >= 300) {

EntityUtils.consume(entity);

throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase());

}

return entity == null ? null : EntityUtils.toString(entity, Consts.UTF_8);

}

開發者ID:11590692,項目名稱:Wechat-Group,代碼行數:11,

示例8: ResponseImpl

​點讚 2

import org.apache.http.StatusLine; //導入方法依賴的package包/類

public ResponseImpl(HttpResponse response, HttpRequestBase httpMethod)

{

this.httpMethod = httpMethod;

this.response = response;

if( response != null )

{

final StatusLine statusLine = response.getStatusLine();

this.code = statusLine.getStatusCode();

this.message = statusLine.getReasonPhrase();

}

}

開發者ID:equella,項目名稱:Equella,代碼行數:12,

示例9: validateResponse

​點讚 2

import org.apache.http.StatusLine; //導入方法依賴的package包/類

/**

* Validate the given response as contained in the HttpPost object,

* throwing an exception if it does not correspond to a successful HTTP response.

*

Default implementation rejects any HTTP status code beyond 2xx, to avoid

* parsing the response body and trying to deserialize from a corrupted stream.

* @param config the HTTP invoker configuration that specifies the target service

* @param response the resulting HttpResponse to validate

* @throws java.io.IOException if validation failed

*/

protected void validateResponse(HttpInvokerClientConfiguration config, HttpResponse response)

throws IOException {

StatusLine status = response.getStatusLine();

if (status.getStatusCode() >= 300) {

throw new NoHttpResponseException(

"Did not receive successful HTTP response: status code = " + status.getStatusCode() +

", status message = [" + status.getReasonPhrase() + "]");

}

}

示例10: handleResponse

​點讚 2

import org.apache.http.StatusLine; //導入方法依賴的package包/類

/**

* Returns the response body as a String if the response was successful (a

* 2xx status code). If no response body exists, this returns null. If the

* response was unsuccessful (>= 300 status code), throws an

* {@link HttpResponseException}.

*/

public String handleResponse(final HttpResponse response)

throws HttpResponseException, IOException {

StatusLine statusLine = response.getStatusLine();

HttpEntity entity = response.getEntity();

if (statusLine.getStatusCode() >= 300) {

EntityUtils.consume(entity);

throw new HttpResponseException(statusLine.getStatusCode(),

statusLine.getReasonPhrase());

}

return entity == null ? null : EntityUtils.toString(entity);

}

開發者ID:lamsfoundation,項目名稱:lams,代碼行數:18,

示例11: handleResponse

​點讚 2

import org.apache.http.StatusLine; //導入方法依賴的package包/類

@Override

public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException {

final StatusLine statusLine = response.getStatusLine();

int status = statusLine.getStatusCode();

if (status >= 200 && status < 300) {

HttpEntity entity = response.getEntity();

return entity != null ? EntityUtils.toString(entity) : null;

} else {

throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase());

}

}

開發者ID:Code4SocialGood,項目名稱:c4sg-services,代碼行數:12,

示例12: handleResponse

​點讚 2

import org.apache.http.StatusLine; //導入方法依賴的package包/類

@SuppressWarnings("unchecked")

private ResponseInfo handleResponse(HttpResponse response) throws HttpException, IOException {

if (response == null) {

throw new HttpException("response is null");

}

if (isCancelled()) return null;

StatusLine status = response.getStatusLine();

int statusCode = status.getStatusCode();

if (statusCode < 300) {

Object result = null;

HttpEntity entity = response.getEntity();

if (entity != null) {

isUploading = false;

if (isDownloadingFile) {

autoResume = autoResume && OtherUtils.isSupportRange(response);

String responseFileName = autoRename ? OtherUtils.getFileNameFromHttpResponse(response) : null;

result = mFileDownloadHandler.handleEntity(entity, this, fileSavePath, autoResume, responseFileName);

} else {

// Set charset from response header info if it's exist.

String responseCharset = OtherUtils.getCharsetFromHttpResponse(response);

charset = TextUtils.isEmpty(responseCharset) ? charset : responseCharset;

result = mStringDownloadHandler.handleEntity(entity, this, charset);

HttpUtils.sHttpGetCache.put(requestUrl, (String) result, expiry);

}

}

return new ResponseInfo(response, (T) result, false);

} else if (statusCode == 301 || statusCode == 302) {

if (httpRedirectHandler == null) {

httpRedirectHandler = new DefaultHttpRedirectHandler();

}

HttpRequestBase request = httpRedirectHandler.getDirectRequest(response);

if (request != null) {

return this.sendRequest(request);

}

} else if (statusCode == 416) {

throw new HttpException(statusCode, "maybe the file has downloaded completely");

} else {

throw new HttpException(statusCode, status.getReasonPhrase());

}

return null;

}

開發者ID:SavorGit,項目名稱:Hotspot-master-devp,代碼行數:45,

示例13: adaptStatus

​點讚 2

import org.apache.http.StatusLine; //導入方法依賴的package包/類

private StatusCodeLine adaptStatus(StatusLine statusLine) {

return new StatusCodeLine(statusLine.getProtocolVersion().toString(),

statusLine.getStatusCode(), statusLine.getReasonPhrase());

}

開發者ID:renatoathaydes,項目名稱:rawhttp,代碼行數:5,

注:本文中的org.apache.http.StatusLine.getReasonPhrase方法示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值