當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。