use of cz.msebera.android.httpclient.message.BasicHeader in project android-async-http by loopj.
the class SampleParentActivity method getRequestHeadersList.
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;
}
use of cz.msebera.android.httpclient.message.BasicHeader in project android-async-http by loopj.
the class Http401AuthSample method getRequestHeaders.
@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()]);
}
use of cz.msebera.android.httpclient.message.BasicHeader in project android-sex-http by dtboy1995.
the class MainActivity method init.
// 注册该接收者
void init() {
// init the global cache
HTTPUtil.initHttpCache(this);
HTTPUtil.BASE_URL = "http://apistage.wenanle.com";
HTTPUtil.globalResponseHandler = new IGlobalResponseHandler() {
@Override
public void disconnected(Context context) {
Toast.makeText(context, "no networking!", Toast.LENGTH_SHORT).show();
}
@Override
public void fail(String response, Context context) {
Toast.makeText(context, "error happened!", Toast.LENGTH_SHORT).show();
}
};
HTTPUtil.globalRequestHandler = new IGlobalRequestHandler() {
@Override
public List<Header> addHeaders() {
List<Header> headers = new ArrayList<>();
headers.add(new BasicHeader("version", "1.0.2"));
// add ...
return headers;
}
};
}
use of cz.msebera.android.httpclient.message.BasicHeader in project android-sex-http by dtboy1995.
the class Request method setHeaders.
public Request setHeaders(Map<String, String> headers) {
this.headers.clear();
for (Map.Entry<String, String> header : headers.entrySet()) {
Header h = new BasicHeader(header.getKey(), header.getValue());
this.headers.add(h);
}
return this;
}
Aggregations