当前位置: 首页>>代码示例>>Java>>正文


Java HttpRequest.header方法代码示例

本文整理汇总了Java中com.github.kevinsawicki.http.HttpRequest.header方法的典型用法代码示例。如果您正苦于以下问题:Java HttpRequest.header方法的具体用法?Java HttpRequest.header怎么用?Java HttpRequest.header使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.github.kevinsawicki.http.HttpRequest的用法示例。


在下文中一共展示了HttpRequest.header方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: uploadMeasurements

import com.github.kevinsawicki.http.HttpRequest; //导入方法依赖的package包/类
@Override
public RequestResult uploadMeasurements(String content) {
    Log.d("uploadMeasurements(): Sending post request");
    try {
        HttpRequest request = HttpRequest.post(uploadUrl)
                .followRedirects(false)
                .connectTimeout(CONN_TIMEOUT)
                .readTimeout(READ_TIMEOUT);
        // add json as request content
        request.header("Content-Type", "application/json");
        request.send(content);
        return handleResponse(request.code(), request.body());
    } catch (HttpRequestException ex) {
        Log.d("uploadMeasurements(): Errors encountered", ex);
        reportExceptionWithSuppress(ex);
        return RequestResult.Failure;
    }
}
 
开发者ID:zamojski,项目名称:TowerCollector,代码行数:19,代码来源:MozillaUploadClient.java

示例2: addCredentialsTo

import com.github.kevinsawicki.http.HttpRequest; //导入方法依赖的package包/类
private HttpRequest addCredentialsTo(HttpRequest request) {

        // Required params for
        request.header(HEADER_PARSE_REST_API_KEY, PARSE_REST_API_KEY);
        request.header(HEADER_PARSE_APP_ID, PARSE_APP_ID);

        /**
         * NOTE: This may be where you want to add a header for the api token that was saved when you
         * logged in. In the bootstrap sample this is where we are saving the session id as the token.
         * If you actually had received a token you'd take the "apiKey" (aka: token) and add it to the
         * header or form values before you make your requests.
         */

        /**
         * Add the user name and password to the request here if your service needs username or password for each
         * request. You can do this like this:
         * request.basic("myusername", "mypassword");
         */

        return request;
    }
 
开发者ID:echopen,项目名称:PRJ-medtec_androidapp,代码行数:22,代码来源:BootstrapService.java

示例3: prepareHttpRequest

import com.github.kevinsawicki.http.HttpRequest; //导入方法依赖的package包/类
public static HttpRequest prepareHttpRequest(final Request request) throws IOException {

        // Extract details from incoming request from Retrofit
        final String requestUrl = request.getUrl();
        final String requestMethod = request.getMethod();
        final List<Header> requestHeaders = request.getHeaders();

        // URL and Method
        final HttpRequest httpRequest = new HttpRequest(requestUrl, requestMethod);

        // Headers
        for (Header header: requestHeaders) {
            httpRequest.header(header.getName(), header.getValue());
        }

        return httpRequest;
    }
 
开发者ID:groodt,项目名称:http-request-retrofit-client,代码行数:18,代码来源:HttpRequestClient.java

示例4: test02

import com.github.kevinsawicki.http.HttpRequest; //导入方法依赖的package包/类
@Test
public void test02() throws Exception {
    //49
    ObjectMapper mapper = new ObjectMapper();
    List<String> ret = new ArrayList<>();
    String url = "https://xueqiu.com/stock/cata/stocklist.json?page=";
    String param = "&size=100&order=desc&orderby=percent&type=11%2C12&_=1461851096446";
    for (int i = 1; i <= 50; i++) {
        String dest = url + i + param;
        HttpRequest req = HttpRequest.get(dest);
        req.header("Cookie", "xq_a_token=93b9123bccf67168e3adb0c07d89b9e1f6cc8db6;");
        String body = req.body();
        ret.add(body);

        JsonNode jsonNode = mapper.readTree(body);
        JsonNode stocks = jsonNode.get("stocks");
        stocks.forEach(st->{
            Stock stock = null;
            try {
                stock = mapper.readValue(st.toString(), Stock.class);
                DaoUtil.dao.insert(stock);
            } catch (Exception e) {
                e.printStackTrace();
            }

        });
        Thread.sleep(500);
        System.out.println("fetch url " + dest + " result " + body);

    }
    System.out.println("final result---> " + mapper.writeValueAsString(ret));

}
 
开发者ID:jt120,项目名称:take,代码行数:34,代码来源:LoginTest.java

示例5: prepareApiRequest

import com.github.kevinsawicki.http.HttpRequest; //导入方法依赖的package包/类
/**
 * Prepares an arbitrary API request by injecting an ID Token into an HttpRequest. Uses an
 * external library to make my life easier, but you can modify this to use whatever in case you
 * don't like the (small) dependency.
 */
public static HttpRequest prepareApiRequest(HttpRequest request, String idToken, String cookies)
        throws IOException {

    request = request.authorization("Bearer " + idToken).acceptJson();
    request = request.header("Cookie", cookies);
    return request;
}
 
开发者ID:tdb-alcorn,项目名称:defect-party,代码行数:13,代码来源:APIUtility.java

示例6: setHeadersFromJsonObject

import com.github.kevinsawicki.http.HttpRequest; //导入方法依赖的package包/类
protected void setHeadersFromJsonObject(HttpRequest request, JSONObject headers) throws JSONException
{
    Iterator<?> keys = headers.keys();
    while(keys.hasNext()) {
        String key = (String) keys.next();
        request.header(key, (String) headers.get(key));
    }
}
 
开发者ID:spiffyjr,项目名称:packmule,代码行数:9,代码来源:AbstractHttp.java


注:本文中的com.github.kevinsawicki.http.HttpRequest.header方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。