Search in sources :

Example 1 with BasicHeader

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;
}
Also used : Header(cz.msebera.android.httpclient.Header) BasicHeader(cz.msebera.android.httpclient.message.BasicHeader) ArrayList(java.util.ArrayList) BasicHeader(cz.msebera.android.httpclient.message.BasicHeader)

Example 2 with BasicHeader

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()]);
}
Also used : Header(cz.msebera.android.httpclient.Header) BasicHeader(cz.msebera.android.httpclient.message.BasicHeader) BasicHeader(cz.msebera.android.httpclient.message.BasicHeader)

Example 3 with BasicHeader

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;
        }
    };
}
Also used : Context(android.content.Context) IGlobalRequestHandler(com.prajna.dtboy.http.IGlobalRequestHandler) ArrayList(java.util.ArrayList) List(java.util.List) IGlobalResponseHandler(com.prajna.dtboy.http.IGlobalResponseHandler) BasicHeader(cz.msebera.android.httpclient.message.BasicHeader)

Example 4 with BasicHeader

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;
}
Also used : Header(cz.msebera.android.httpclient.Header) BasicHeader(cz.msebera.android.httpclient.message.BasicHeader) Map(java.util.Map) BasicHeader(cz.msebera.android.httpclient.message.BasicHeader)

Aggregations

BasicHeader (cz.msebera.android.httpclient.message.BasicHeader)4 Header (cz.msebera.android.httpclient.Header)3 ArrayList (java.util.ArrayList)2 Context (android.content.Context)1 IGlobalRequestHandler (com.prajna.dtboy.http.IGlobalRequestHandler)1 IGlobalResponseHandler (com.prajna.dtboy.http.IGlobalResponseHandler)1 List (java.util.List)1 Map (java.util.Map)1