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


Java HttpRequest.form方法代码示例

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


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

示例1: post

import com.github.kevinsawicki.http.HttpRequest; //导入方法依赖的package包/类
/**
 * 构造POST提交表单请求,返回响应结果
 * @param params
 * 提交的参数
 * @param address
 * 提交的地址
 * @param connectTimeout
 * @param readTimeout
 * @return
 */
public static HttpResult post(Map<String,String> params,String address,int connectTimeout,int readTimeout) throws IOException {
    HttpResult result = new HttpResult();
    if(params == null){
        params = new HashMap<>();
    }
    if(StringUtils.isEmpty(address)){
        log.error("请求地址不能为空");
        return null;
    }
    URL requestUrl = new URL(address);
    long start = System.currentTimeMillis();
    HttpRequest httpRequest = new HttpRequest(requestUrl,"POST")
            .connectTimeout(connectTimeout).readTimeout(readTimeout).trustAllCerts().trustAllHosts();
    httpRequest.form(params,"UTF-8");
    result.setStatus(httpRequest.code());
    result.setResult(httpRequest.body());
    result.setResponseTime(System.currentTimeMillis() - start);
    return result;
}
 
开发者ID:DevopsJK,项目名称:SuitAgent,代码行数:30,代码来源:HttpUtil.java

示例2: request

import com.github.kevinsawicki.http.HttpRequest; //导入方法依赖的package包/类
/**
 * Make request
 * @param url String
 * @param requestType RequestType
 * @param data Map<String, String>
 * @param callback Request
 */
private void request(String url, RequestType requestType, Map<String, String> data, final Request callback) {

    url = API_URL + url;

    String authorization = null;

    switch(asanaClient.getConnectionType()) {
        case API_KEY:
            authorization = "Basic " + Base64.encode(asanaClient.getApiKey().getBytes());
            break;
        case TOKEN:
            authorization = "Bearer " + asanaClient.getToken();
            break;
    }

    HttpRequest httpRequest;

    switch(requestType) {
        case POST:
            httpRequest = HttpRequest.post(url).header("Authorization", authorization);
            httpRequest.form(data);
            if(httpRequest.ok()) {
                callback.onSuccess(httpRequest.body());
            }
            break;
        case GET:
            httpRequest = HttpRequest.get(url).header("Authorization", authorization);
            if(httpRequest.ok()) {
                callback.onSuccess(httpRequest.body());
            }
            break;
        case PUT:
            httpRequest = HttpRequest.put(url).header("Authorization", authorization);
            httpRequest.form(data);
            if(httpRequest.ok()) {
                callback.onSuccess(httpRequest.body());
            }
            break;
    }
}
 
开发者ID:DawidSajdak,项目名称:AsanaJavaClient,代码行数:48,代码来源:AsanaRequest.java

示例3: post

import com.github.kevinsawicki.http.HttpRequest; //导入方法依赖的package包/类
/**
 * (http) post
 * @param address       The address of the API
 * @param apiKey        The username for basic authentication
 * @param apiPassword   The password for basic authentication
 * @param body          The request body of the API
 * @param requestType   The URI part of the API method
 * @return              The request object
 * @throws Exception
 */
public HttpRequest post(String address, String apiKey, String apiPassword, Map body, String requestType) throws Exception {
    HttpRequest request = HttpRequest.post(new URL(address));
    request.basic(apiKey, apiPassword);
    request.accept(String.format("application/%s", requestType));
    request.form(body);
    return request;
}
 
开发者ID:kfrancis,项目名称:Chargify.Java,代码行数:18,代码来源:Requester.java

示例4: put

import com.github.kevinsawicki.http.HttpRequest; //导入方法依赖的package包/类
/**
 * (http) put
 * @param address       The address of the API
 * @param apiKey        The username for basic authentication
 * @param apiPassword   The password for basic authentication
 * @param body          The request body of the API
 * @param requestType   The URI part of the API method
 * @return              The request object
 * @throws Exception
 */
public HttpRequest put(String address, String apiKey, String apiPassword, Map body, String requestType) throws Exception {
    HttpRequest request = HttpRequest.put(new URL(address));
    request.basic(apiKey, apiPassword);
    request.accept(String.format("application/%s", requestType));
    request.form(body);
    return request;
}
 
开发者ID:kfrancis,项目名称:Chargify.Java,代码行数:18,代码来源:Requester.java


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