本文整理汇总了Java中cz.msebera.android.httpclient.message.BasicHeader类的典型用法代码示例。如果您正苦于以下问题:Java BasicHeader类的具体用法?Java BasicHeader怎么用?Java BasicHeader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BasicHeader类属于cz.msebera.android.httpclient.message包,在下文中一共展示了BasicHeader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRequestHeadersList
import cz.msebera.android.httpclient.message.BasicHeader; //导入依赖的package包/类
public List<Header> getRequestHeadersList() {
List<Header> headers = new ArrayList<Header>();
String headersRaw = headersEditText.getText() == null ? null : headersEditText.getText().toString();
if (headersRaw != null && headersRaw.length() > 3) {
String[] lines = headersRaw.split("\\r?\\n");
for (String line : lines) {
try {
int equalSignPos = line.indexOf('=');
if (1 > equalSignPos) {
throw new IllegalArgumentException("Wrong header format, may be 'Key=Value' only");
}
String headerName = line.substring(0, equalSignPos).trim();
String headerValue = line.substring(1 + equalSignPos).trim();
Log.d(LOG_TAG, String.format("Added header: [%s:%s]", headerName, headerValue));
headers.add(new BasicHeader(headerName, headerValue));
} catch (Throwable t) {
Log.e(LOG_TAG, "Not a valid header line: " + line, t);
}
}
}
return headers;
}
示例2: getRequestHeaders
import cz.msebera.android.httpclient.message.BasicHeader; //导入依赖的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()]);
}
示例3: deserializeHeaders
import cz.msebera.android.httpclient.message.BasicHeader; //导入依赖的package包/类
public static Header[] deserializeHeaders(String[] serialized) {
if (serialized == null || serialized.length % 2 != 0) {
return new Header[0];
}
Header[] headers = new Header[serialized.length / 2];
for (int i = 0, h = 0; h < headers.length; i++, h++) {
headers[h] = new BasicHeader(serialized[i], serialized[++i]);
}
return headers;
}
示例4: setAuthentication
import cz.msebera.android.httpclient.message.BasicHeader; //导入依赖的package包/类
/**
* Set the different fields that are used for the various API calls.
*
* @param ctx The context used to make the requests.
* @param app_id App Id from the Kairos developer dashboard.
* @param api_key Api Key from the Kairos developer dashboard.
*/
public void setAuthentication(Context ctx, String app_id, String api_key) {
this.my_context = ctx;
this.my_app_id = app_id;
this.my_api_key = api_key;
this.my_host = "http://api.kairos.com/";
mHeaders = new Header[]{new BasicHeader("Content-Type", "application/json"), new BasicHeader("app_id", my_app_id), new BasicHeader("app_key", my_api_key)};
}
示例5: deletePost
import cz.msebera.android.httpclient.message.BasicHeader; //导入依赖的package包/类
@Override
public String deletePost(DeletePostModel model, ProgressListener listener, CancellableTask task) throws Exception {
String url = getUsingUrl() + "post.php";
List<NameValuePair> pairs = new ArrayList<NameValuePair>();
pairs.add(new BasicNameValuePair("board", model.boardName));
pairs.add(new BasicNameValuePair("delete_" + model.postNumber, "on"));
if (model.onlyFiles) pairs.add(new BasicNameValuePair("file", "on"));
pairs.add(new BasicNameValuePair("password", model.password));
pairs.add(new BasicNameValuePair("delete", getDeleteFormValue(model)));
pairs.add(new BasicNameValuePair("reason", ""));
UrlPageModel refererPage = new UrlPageModel();
refererPage.type = UrlPageModel.TYPE_THREADPAGE;
refererPage.chanName = getChanName();
refererPage.boardName = model.boardName;
refererPage.threadNumber = model.threadNumber;
Header[] customHeaders = new Header[] { new BasicHeader(HttpHeaders.REFERER, buildUrl(refererPage)) };
HttpRequestModel rqModel = HttpRequestModel.builder().
setPOST(new UrlEncodedFormEntity(pairs, "UTF-8")).setCustomHeaders(customHeaders).setNoRedirect(true).build();
HttpResponseModel response = null;
try {
response = HttpStreamer.getInstance().getFromUrl(url, rqModel, httpClient, listener, task);
if (response.statusCode == 200 || response.statusCode == 400 || response.statusCode == 303) {
ByteArrayOutputStream output = new ByteArrayOutputStream(1024);
IOUtils.copyStream(response.stream, output);
String htmlResponse = output.toString("UTF-8");
Matcher errorMatcher = ERROR_PATTERN.matcher(htmlResponse);
if (errorMatcher.find()) throw new Exception(errorMatcher.group(1));
return null;
}
throw new Exception(response.statusCode + " - " + response.statusReason);
} finally {
if (response != null) response.release();
}
}
示例6: reportPost
import cz.msebera.android.httpclient.message.BasicHeader; //导入依赖的package包/类
@Override
public String reportPost(DeletePostModel model, ProgressListener listener, CancellableTask task) throws Exception {
String url = getUsingUrl() + "post.php";
List<NameValuePair> pairs = new ArrayList<NameValuePair>();
pairs.add(new BasicNameValuePair("board", model.boardName));
pairs.add(new BasicNameValuePair("delete_" + model.postNumber, "on"));
pairs.add(new BasicNameValuePair("password", ""));
pairs.add(new BasicNameValuePair("reason", model.reportReason));
pairs.add(new BasicNameValuePair("report", getReportFormValue(model)));
UrlPageModel refererPage = new UrlPageModel();
refererPage.type = UrlPageModel.TYPE_THREADPAGE;
refererPage.chanName = getChanName();
refererPage.boardName = model.boardName;
refererPage.threadNumber = model.threadNumber;
Header[] customHeaders = new Header[] { new BasicHeader(HttpHeaders.REFERER, buildUrl(refererPage)) };
HttpRequestModel rqModel = HttpRequestModel.builder().
setPOST(new UrlEncodedFormEntity(pairs, "UTF-8")).setCustomHeaders(customHeaders).setNoRedirect(true).build();
HttpResponseModel response = null;
try {
response = HttpStreamer.getInstance().getFromUrl(url, rqModel, httpClient, listener, task);
if (response.statusCode == 200 || response.statusCode == 400 || response.statusCode == 303) {
ByteArrayOutputStream output = new ByteArrayOutputStream(1024);
IOUtils.copyStream(response.stream, output);
String htmlResponse = output.toString("UTF-8");
Matcher errorMatcher = ERROR_PATTERN.matcher(htmlResponse);
if (errorMatcher.find()) throw new Exception(errorMatcher.group(1));
return null;
}
throw new Exception(response.statusCode + " - " + response.statusReason);
} finally {
if (response != null) response.release();
}
}
示例7: getAdapter
import cz.msebera.android.httpclient.message.BasicHeader; //导入依赖的package包/类
@Override
protected ImagePagerAdapter getAdapter() {
for (int i = 0; i < urls.size(); i++) {
urls.set(i, urls.get(i).replace("c/240x480/img-master", "img-original").replace("_master1200", ""));
}
return new ImagePagerAdapter(this, urls, new Header[]{new BasicHeader("Referer", Constants.BASE_API_PIXIV)});
}
示例8: prepareHeaders
import cz.msebera.android.httpclient.message.BasicHeader; //导入依赖的package包/类
/**
* Ensure all required headers are present
*
* @param additionalHeaders List of headers specific to a single request
* @return Complete list of headers necessary for API request
*/
private Header[] prepareHeaders(ArrayList<Header> additionalHeaders) {
BasicHeader defaultHeader = new BasicHeader("Host", host);
if (additionalHeaders != null) {
ArrayList<Header> headers =
(ArrayList<Header>) additionalHeaders.clone();
headers.add(defaultHeader);
return headers.toArray(new Header[headers.size()]);
} else {
return new Header[]{defaultHeader};
}
}
示例9: createBasicAuthenticationHeader
import cz.msebera.android.httpclient.message.BasicHeader; //导入依赖的package包/类
private Header createBasicAuthenticationHeader(String username,
String password) {
String credentials = String.format("%s:%s", username, password);
String encoded = Base64.encodeToString(credentials.getBytes(),
Base64.NO_WRAP);
return new BasicHeader("Authorization", String.format("%s %s", "Basic", encoded));
}
示例10: getContentType
import cz.msebera.android.httpclient.message.BasicHeader; //导入依赖的package包/类
@Override
public Header getContentType() {
return new BasicHeader(
AsyncHttpClient.HEADER_CONTENT_TYPE,
"multipart/form-data; boundary=" + boundary);
}
示例11: tokenizeCard
import cz.msebera.android.httpclient.message.BasicHeader; //导入依赖的package包/类
void tokenizeCard(JSONObject jsonObject, AsyncHttpResponseHandler responseHandler) throws JSONException, UnsupportedEncodingException {
ByteArrayEntity entity = new ByteArrayEntity(jsonObject.toString().getBytes("UTF-8"));
entity.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
httpClient.put(null, url + CARD_TOKENIZE + merchantToken, entity, "application/json", responseHandler);
}
示例12: sendPost
import cz.msebera.android.httpclient.message.BasicHeader; //导入依赖的package包/类
@Override
public String sendPost(SendPostModel model, ProgressListener listener, CancellableTask task) throws Exception {
UrlPageModel urlModel = new UrlPageModel();
urlModel.chanName = getChanName();
urlModel.boardName = model.boardName;
if (model.threadNumber == null) {
urlModel.type = UrlPageModel.TYPE_BOARDPAGE;
urlModel.boardPage = UrlPageModel.DEFAULT_FIRST_PAGE;
} else {
urlModel.type = UrlPageModel.TYPE_THREADPAGE;
urlModel.threadNumber = model.threadNumber;
}
String referer = buildUrl(urlModel);
List<Pair<String, String>> fields = VichanAntiBot.getFormValues(referer, task, httpClient);
if (task != null && task.isCancelled()) throw new Exception("interrupted");
ExtendedMultipartBuilder postEntityBuilder = ExtendedMultipartBuilder.create().
setCharset(Charset.forName("UTF-8")).setDelegates(listener, task);
for (Pair<String, String> pair : fields) {
if (pair.getKey().equals("spoiler") && !model.custommark) continue;
String val;
switch (pair.getKey()) {
case "name": val = model.name; break;
case "email": val = getSendPostEmail(model); break;
case "subject": val = model.subject; break;
case "body": val = model.comment; break;
case "password": val = model.password; break;
case "spoiler": val = "on"; break;
default: val = pair.getValue();
}
if (pair.getKey().equals("file")) {
if (model.attachments != null && model.attachments.length > 0) {
postEntityBuilder.addFile(pair.getKey(), model.attachments[0], model.randomHash);
} else {
postEntityBuilder.addPart(pair.getKey(), new ByteArrayBody(new byte[0], ""));
}
} else {
postEntityBuilder.addString(pair.getKey(), val);
}
}
String url = getUsingUrl() + "post.php";
Header[] customHeaders = new Header[] { new BasicHeader(HttpHeaders.REFERER, referer) };
HttpRequestModel request =
HttpRequestModel.builder().setPOST(postEntityBuilder.build()).setCustomHeaders(customHeaders).setNoRedirect(true).build();
HttpResponseModel response = null;
try {
response = HttpStreamer.getInstance().getFromUrl(url, request, httpClient, listener, task);
if (response.statusCode == 200 || response.statusCode == 400) {
ByteArrayOutputStream output = new ByteArrayOutputStream(1024);
IOUtils.copyStream(response.stream, output);
String htmlResponse = output.toString("UTF-8");
Matcher errorMatcher = ERROR_PATTERN.matcher(htmlResponse);
if (errorMatcher.find()) throw new Exception(errorMatcher.group(1));
} else if (response.statusCode == 303) {
for (Header header : response.headers) {
if (header != null && HttpHeaders.LOCATION.equalsIgnoreCase(header.getName())) {
return fixRelativeUrl(header.getValue());
}
}
}
throw new Exception(response.statusCode + " - " + response.statusReason);
} finally {
if (response != null) response.release();
}
}
示例13: sendPost
import cz.msebera.android.httpclient.message.BasicHeader; //导入依赖的package包/类
@Override
public String sendPost(SendPostModel model, ProgressListener listener, CancellableTask task) throws Exception {
int bVal = (int) (Math.random() * 10000);
String banana = HttpStreamer.getInstance().getJSONObjectFromUrl((useHttps() ? "https://" : "http://") + "boards.420chan.org/bunker/",
HttpRequestModel.builder().
setPOST(new UrlEncodedFormEntity(Collections.singletonList(new BasicNameValuePair("b", Integer.toString(bVal))), "UTF-8")).
setCustomHeaders(new Header[] { new BasicHeader("X-Requested-With", "XMLHttpRequest") }).
build(), httpClient, null, task, false).optString("response");
String url = (useHttps() ? "https://" : "http://") + "boards.420chan.org/" + model.boardName + "/taimaba.pl";
ExtendedMultipartBuilder postEntityBuilder = ExtendedMultipartBuilder.create().setDelegates(listener, task).
addString("board", model.boardName).
addString("task", "post").
addString("password", model.password);
if (model.threadNumber != null) postEntityBuilder.addString("parent", model.threadNumber);
postEntityBuilder.
addString("field1", model.name).
addString("field3", model.subject).
addString("field4", model.comment);
if (model.attachments != null && model.attachments.length > 0)
postEntityBuilder.addFile("file", model.attachments[0], model.randomHash);
if (model.sage) postEntityBuilder.addString("sage", "on");
postEntityBuilder.addString("banana", banana);
HttpRequestModel request = HttpRequestModel.builder().setPOST(postEntityBuilder.build()).setNoRedirect(true).build();
HttpResponseModel response = null;
try {
response = HttpStreamer.getInstance().getFromUrl(url, request, httpClient, null, task);
if (response.statusCode == 302) {
return null;
} else if (response.statusCode == 200) {
ByteArrayOutputStream output = new ByteArrayOutputStream(1024);
IOUtils.copyStream(response.stream, output);
String htmlResponse = output.toString("UTF-8");
Matcher errorMatcher = ERROR_PATTERN.matcher(htmlResponse);
if (errorMatcher.find()) throw new Exception(errorMatcher.group(1));
} else throw new Exception(response.statusCode + " - " + response.statusReason);
} finally {
if (response != null) response.release();
}
return null;
}
示例14: sendPost
import cz.msebera.android.httpclient.message.BasicHeader; //导入依赖的package包/类
@Override
public String sendPost(SendPostModel model, ProgressListener listener, CancellableTask task) throws Exception {
UrlPageModel urlModel = new UrlPageModel();
urlModel.chanName = CHAN_NAME;
urlModel.boardName = model.boardName;
if (model.threadNumber == null) {
urlModel.type = UrlPageModel.TYPE_BOARDPAGE;
urlModel.boardPage = UrlPageModel.DEFAULT_FIRST_PAGE;
} else {
urlModel.type = UrlPageModel.TYPE_THREADPAGE;
urlModel.threadNumber = model.threadNumber;
}
String referer = buildUrl(urlModel);
List<Pair<String, String>> fields = VichanAntiBot.getFormValues(referer, task, httpClient);
if (task != null && task.isCancelled()) throw new Exception("interrupted");
ExtendedMultipartBuilder postEntityBuilder = ExtendedMultipartBuilder.create().
setCharset(Charset.forName("UTF-8")).setDelegates(listener, task);
for (Pair<String, String> pair : fields) {
if (pair.getKey().equals("spoiler")) continue;
String val;
switch (pair.getKey()) {
case "subject": val = model.subject; break;
case "body": val = model.comment; break;
case "password": val = model.password; break;
default: val = pair.getValue();
}
int i = 1;
String fileNo;
switch (pair.getKey()) {
case "file": case "file2": case "file3": case "file4":
fileNo = pair.getKey().replaceAll("[\\D]", "");
if (fileNo != "") {
i = Integer.parseInt(fileNo);
}
if (model.attachments == null || model.attachments.length < i) {
postEntityBuilder.addPart(pair.getKey(), new ByteArrayBody(new byte[0], ""));
} else {
postEntityBuilder.addFile(pair.getKey(), model.attachments[i - 1], model.randomHash);
}
break;
default:
postEntityBuilder.addString(pair.getKey(), val);
}
}
String url = getUsingUrl() + "post.php";
Header[] customHeaders = new Header[] { new BasicHeader(HttpHeaders.REFERER, referer) };
HttpRequestModel request =
HttpRequestModel.builder().setPOST(postEntityBuilder.build()).setCustomHeaders(customHeaders).setNoRedirect(true).build();
HttpResponseModel response = null;
try {
response = HttpStreamer.getInstance().getFromUrl(url, request, httpClient, listener, task);
if (response.statusCode == 200 || response.statusCode == 400) {
ByteArrayOutputStream output = new ByteArrayOutputStream(1024);
IOUtils.copyStream(response.stream, output);
String htmlResponse = output.toString("UTF-8");
Matcher errorMatcher = ERROR_PATTERN.matcher(htmlResponse);
if (errorMatcher.find()) throw new Exception(errorMatcher.group(1));
} else if (response.statusCode == 303) {
for (Header header : response.headers) {
if (header != null && HttpHeaders.LOCATION.equalsIgnoreCase(header.getName())) {
return fixRelativeUrl(header.getValue());
}
}
}
throw new Exception(response.statusCode + " - " + response.statusReason);
} finally {
if (response != null) response.release();
}
}
示例15: sendPost
import cz.msebera.android.httpclient.message.BasicHeader; //导入依赖的package包/类
@Override
public String sendPost(SendPostModel model, ProgressListener listener, CancellableTask task) throws Exception {
if (task != null && task.isCancelled()) throw new InterruptedException("interrupted");
String url = getUsingUrl() + "post.php";
ExtendedMultipartBuilder postEntityBuilder = ExtendedMultipartBuilder.create().setDelegates(listener, task).
addString("name", model.name).
addString("email", model.sage ? "sage" : model.email).
addString("subject", model.subject).
addString("body", model.comment).
addString("post", model.threadNumber == null ? "New Topic" : "New Reply").
addString("board", model.boardName);
if (model.threadNumber != null) postEntityBuilder.addString("thread", model.threadNumber);
if (model.custommark) postEntityBuilder.addString("spoiler", "on");
postEntityBuilder.addString("password", TextUtils.isEmpty(model.password) ? getDefaultPassword() : model.password).
addString("message", "").
addString("json_response", "1");
if (model.attachments != null) {
String[] images = new String[] { "file", "file2", "file3", "file4", "file5" };
for (int i=0; i<model.attachments.length; ++i) {
postEntityBuilder.addFile(images[i], model.attachments[i], model.randomHash);
}
}
UrlPageModel refererPage = new UrlPageModel();
refererPage.chanName = getChanName();
refererPage.boardName = model.boardName;
if (model.threadNumber == null) {
refererPage.type = UrlPageModel.TYPE_BOARDPAGE;
refererPage.boardPage = UrlPageModel.DEFAULT_FIRST_PAGE;
} else {
refererPage.type = UrlPageModel.TYPE_THREADPAGE;
refererPage.threadNumber = model.threadNumber;
}
Header[] customHeaders = new Header[] { new BasicHeader(HttpHeaders.REFERER, buildUrl(refererPage)) };
HttpRequestModel request =
HttpRequestModel.builder().setPOST(postEntityBuilder.build()).setCustomHeaders(customHeaders).setNoRedirect(true).build();
JSONObject json = HttpStreamer.getInstance().getJSONObjectFromUrl(url, request, httpClient, listener, task, false);
if (json.has("error")) {
String error = json.getString("error");
if (error.contains("To post on 8chan over Tor, you must use the hidden service for security reasons."))
throw new Exception("To post on 8chan over Tor, you must use the onion domain.");
throw new Exception(error);
} else {
String redirect = json.optString("redirect", "");
if (redirect.length() > 0) return fixRelativeUrl(redirect);
return null;
}
}