本文整理汇总了Java中cz.msebera.android.httpclient.Header类的典型用法代码示例。如果您正苦于以下问题:Java Header类的具体用法?Java Header怎么用?Java Header使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Header类属于cz.msebera.android.httpclient包,在下文中一共展示了Header类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeSample
import cz.msebera.android.httpclient.Header; //导入依赖的package包/类
@Override
public RequestHandle executeSample(AsyncHttpClient client, String URL, Header[] headers, HttpEntity entity, ResponseHandlerInterface responseHandler) {
RequestParams params = new RequestParams();
params.setUseJsonStreamer(true);
JSONObject body;
if (isRequestBodyAllowed() && (body = getBodyTextAsJSON()) != null) {
try {
Iterator keys = body.keys();
Log.d(LOG_TAG, "JSON data:");
while (keys.hasNext()) {
String key = (String) keys.next();
Log.d(LOG_TAG, " " + key + ": " + body.get(key));
params.put(key, body.get(key).toString());
}
} catch (JSONException e) {
Log.w(LOG_TAG, "Unable to retrieve a JSON value", e);
}
}
return client.post(this, URL, headers, params,
RequestParams.APPLICATION_JSON, responseHandler);
}
示例2: onSuccess
import cz.msebera.android.httpclient.Header; //导入依赖的package包/类
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
Graph.AppUsage appUsage = getAppUsage(headers);
if (appUsage != null) {
mLogger.warning(TAG, "Reaching app usage limits: Call: %d%%, Time: %d%%, CPU: %d%%",
appUsage.callCount, appUsage.totalTime, appUsage.totalCPUTime);
appUsage.store(mContext);
}
if (response.has("error")) {
onFailure(statusCode, headers, null, response);
} else {
mResponse = response;
}
}
示例3: getRequestHeaders
import cz.msebera.android.httpclient.Header; //导入依赖的package包/类
@Override
public Header[] getRequestHeaders() {
List<Header> headers = getRequestHeadersList();
// Add authentication header.
if (userName != null && passWord != null) {
byte[] base64bytes = Base64.encode(
(userName + ":" + passWord).getBytes(),
Base64.DEFAULT
);
String credentials = new String(base64bytes);
headers.add(new BasicHeader(HEADER_AUTHORIZATION, HEADER_BASIC + " " + credentials));
}
return headers.toArray(new Header[headers.size()]);
}
示例4: onSuccess
import cz.msebera.android.httpclient.Header; //导入依赖的package包/类
@Override
public void onSuccess(int statusCode, Header[] headers, String responseString) {
try {
Type type = new TypeToken<ResultBean<TweetLikeReverse>>() {
}.getType();
ResultBean<TweetLikeReverse> resultBean = AppOperator.createGson().fromJson(responseString, type);
Tweet tweet = getItem(position);
if (tweet == null) return;
tweet.setLiked(resultBean.getResult().isLiked());
tweet.setLikeCount(resultBean.getResult().getLikeCount());
if (tweet.getStatistics() != null) {
tweet.getStatistics().setLike(resultBean.getResult().getLikeCount());
}
updateItem(position);
} catch (Exception e) {
e.printStackTrace();
onFailure(statusCode, headers, responseString, e);
}
}
示例5: executeSample
import cz.msebera.android.httpclient.Header; //导入依赖的package包/类
@Override
public RequestHandle executeSample(AsyncHttpClient client, String URL, Header[] headers, HttpEntity entity, ResponseHandlerInterface responseHandler) {
try {
RequestParams params = new RequestParams();
final String contentType = RequestParams.APPLICATION_OCTET_STREAM;
params.put("fileOne", createTempFile("fileOne", 1020), contentType, "fileOne");
params.put("fileTwo", createTempFile("fileTwo", 1030), contentType);
params.put("fileThree", createTempFile("fileThree", 1040), contentType, "customFileThree");
params.put("fileFour", createTempFile("fileFour", 1050), contentType);
params.put("fileFive", createTempFile("fileFive", 1060), contentType, "testingFileFive");
params.setHttpEntityIsRepeatable(true);
params.setUseJsonStreamer(false);
return client.post(this, URL, params, responseHandler);
} catch (FileNotFoundException fnfException) {
Log.e(LOG_TAG, "executeSample failed with FileNotFoundException", fnfException);
}
return null;
}
示例6: executeSample
import cz.msebera.android.httpclient.Header; //导入依赖的package包/类
@Override
public RequestHandle executeSample(final AsyncHttpClient client, final String URL, final Header[] headers, HttpEntity entity, final ResponseHandlerInterface responseHandler) {
final Activity ctx = this;
FutureTask<RequestHandle> future = new FutureTask<>(new Callable<RequestHandle>() {
public RequestHandle call() {
Log.d(LOG_TAG, "Executing GET request on background thread");
return client.get(ctx, URL, headers, null, responseHandler);
}
});
executor.execute(future);
RequestHandle handle = null;
try {
handle = future.get(5, TimeUnit.SECONDS);
Log.d(LOG_TAG, "Background thread for GET request has finished");
} catch (Exception e) {
Toast.makeText(ctx, e.getMessage(), Toast.LENGTH_LONG).show();
e.printStackTrace();
}
return handle;
}
示例7: onFailure
import cz.msebera.android.httpclient.Header; //导入依赖的package包/类
@Override
public void onFailure(final int statusCode, final Header[] headers, final byte[] responseBody, final Throwable error) {
// This callback is now running within the pool thread execution
// scope and not within Android's UI thread, so if we must update
// the UI, we'll have to dispatch a runnable to the UI thread.
runOnUiThread(new Runnable() {
@Override
public void run() {
debugStatusCode(LOG_TAG, statusCode);
debugHeaders(LOG_TAG, headers);
debugThrowable(LOG_TAG, error);
if (responseBody != null) {
addView(getColoredView(LIGHTGREEN, "Download interrupted (" + statusCode + "): (bytes=" + responseBody.length + "), path: " + destFile.getAbsolutePath()));
}
}
});
}
示例8: getCookie
import cz.msebera.android.httpclient.Header; //导入依赖的package包/类
/**
* 得到当前的网络请求Cookie,
* 登录后触发
*
* @param headers Header
*/
public static String getCookie(Header[] headers) {
String cookie = getClientCookie(ApiHttpClient.getHttpClient());
if (TextUtils.isEmpty(cookie)) {
cookie = "";
if (headers != null) {
for (Header header : headers) {
String key = header.getName();
String value = header.getValue();
if (key.contains("Set-Cookie"))
cookie += value + ";";
}
if (cookie.length() > 0) {
cookie = cookie.substring(0, cookie.length() - 1);
}
}
}
log("getCookie:" + cookie);
return cookie;
}
示例9: onFailure
import cz.msebera.android.httpclient.Header; //导入依赖的package包/类
@Override
public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
if (errorResponse == null) {
mLogger.error(TAG,"Graph error: failure and empty response (code %d)", statusCode);
return;
}
try {
JSONObject err = errorResponse.getJSONObject("error");
int errCode = err.getInt("code");
if (errCode == 190) {
requestTokenRefresh();
return;
} else if (errorResponse.has("message")) {
mLogger.error(TAG, "Graph error:" + errorResponse.getString("message"));
} else {
mLogger.error(TAG, "Graph error:" + errorResponse.toString());
}
mResponse = errorResponse;
} catch (org.json.JSONException e) {
mLogger.error(TAG, "JSONException: %s", e.getMessage());
}
}
示例10: sendResponseMessage
import cz.msebera.android.httpclient.Header; //导入依赖的package包/类
@Override
public void sendResponseMessage(HttpResponse response) throws IOException {
if (!Thread.currentThread().isInterrupted()) {
StatusLine status = response.getStatusLine();
if (status.getStatusCode() == HttpStatus.SC_REQUESTED_RANGE_NOT_SATISFIABLE) {
//already finished
if (!Thread.currentThread().isInterrupted())
sendSuccessMessage(status.getStatusCode(), response.getAllHeaders(), null);
} else if (status.getStatusCode() >= 300) {
if (!Thread.currentThread().isInterrupted())
sendFailureMessage(status.getStatusCode(), response.getAllHeaders(), null, new HttpResponseException(status.getStatusCode(), status.getReasonPhrase()));
} else {
if (!Thread.currentThread().isInterrupted()) {
Header header = response.getFirstHeader(AsyncHttpClient.HEADER_CONTENT_RANGE);
if (header == null) {
append = false;
current = 0;
} else {
AsyncHttpClient.log.v(LOG_TAG, AsyncHttpClient.HEADER_CONTENT_RANGE + ": " + header.getValue());
}
sendSuccessMessage(status.getStatusCode(), response.getAllHeaders(), getResponseData(response.getEntity()));
}
}
}
}
示例11: onSuccess
import cz.msebera.android.httpclient.Header; //导入依赖的package包/类
@Override
public void onSuccess(int statusCode, Header[] headers, String responseString) {
try {
Type type = new TypeToken<ResultBean<User>>() {
}.getType();
ResultBean resultBean = AppOperator.createGson().fromJson(responseString, type);
if (resultBean.isSuccess()) {
User userInfo = (User) resultBean.getResult();
updateView(userInfo);
//缓存用户信息
AccountHelper.updateUserCache(userInfo);
}
if (mIsUploadIcon) {
deleteCacheImage();
}
} catch (Exception e) {
e.printStackTrace();
onFailure(statusCode, headers, responseString, e);
}
}
示例12: serializeHeaders
import cz.msebera.android.httpclient.Header; //导入依赖的package包/类
public static String[] serializeHeaders(Header[] headers) {
if (headers == null) {
return new String[0];
}
String[] rtn = new String[headers.length * 2];
int index = -1;
for (Header h : headers) {
rtn[++index] = h.getName();
rtn[++index] = h.getValue();
}
return rtn;
}
示例13: debugHeaders
import cz.msebera.android.httpclient.Header; //导入依赖的package包/类
protected final void debugHeaders(String TAG, Header[] headers) {
if (headers != null) {
Log.d(TAG, "Return Headers:");
StringBuilder builder = new StringBuilder();
for (Header h : headers) {
String _h = String.format(Locale.US, "%s : %s", h.getName(), h.getValue());
Log.d(TAG, _h);
builder.append(_h);
builder.append("\n");
}
addView(getColoredView(YELLOW, builder.toString()));
}
}
示例14: executeSample
import cz.msebera.android.httpclient.Header; //导入依赖的package包/类
@Override
public RequestHandle executeSample(AsyncHttpClient client, String URL, Header[] headers, HttpEntity entity, ResponseHandlerInterface responseHandler) {
RequestParams rParams = new RequestParams();
rParams.put("sample_key", "Sample String");
try {
File sample_file = File.createTempFile("temp_", "_handled", getCacheDir());
rParams.put("sample_file", sample_file);
} catch (IOException e) {
Log.e(LOG_TAG, "Cannot add sample file", e);
}
return client.post(this, URL, headers, rParams, "multipart/form-data", responseHandler);
}
示例15: onSuccess
import cz.msebera.android.httpclient.Header; //导入依赖的package包/类
@Override
public void onSuccess(int arg0, Header[] arg1, byte[] arg2) {
// TODO Auto-generated method stub
Result res = XmlUtils.toBean(ResultBean.class, arg2).getResult();
if (res.OK()) {
AppContext.showToast("评论成功");
onRefresh();
} else {
AppContext.showToast(res.getErrorMessage());
}
}