本文整理匯總了Java中org.apache.http.client.fluent.Request.Post方法的典型用法代碼示例。如果您正苦於以下問題:Java Request.Post方法的具體用法?Java Request.Post怎麽用?Java Request.Post使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.http.client.fluent.Request
的用法示例。
在下文中一共展示了Request.Post方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: post
import org.apache.http.client.fluent.Request; //導入方法依賴的package包/類
/**
* Send POST request with authorization header and additional headers
* @param url - The url of the POST request
* @param auth - String for authorization header
* @param headers - Hashmap of headers to add to the request
* @param postData - The body of the POST
* @return the Response to the POST request
*/
public Response post(String url, String auth, HashMap<String, String> headers, JsonJavaObject postData) throws JsonException, IOException, URISyntaxException {
URI normUri = new URI(url).normalize();
Request postRequest = Request.Post(normUri);
//Add all headers
if(StringUtil.isNotEmpty(auth)) {
postRequest.addHeader("Authorization", auth);
}
if(headers != null && headers.size() > 0){
for (Map.Entry<String, String> entry : headers.entrySet()) {
postRequest.addHeader(entry.getKey(), entry.getValue());
}
}
String postDataString = JsonGenerator.toJson(JsonJavaFactory.instanceEx, postData);
Response response = executor.execute(postRequest.bodyString(postDataString, ContentType.APPLICATION_JSON));
return response;
}
示例2: getToken
import org.apache.http.client.fluent.Request; //導入方法依賴的package包/類
public static String getToken(String code){
try{
Request request = Request.Post("https://discordapp.com/api/oauth2/token"
+"?grant_type=authorization_code"
+"&code="+code
+"&redirect_uri="+URLEncoder.encode(Pokebot.config.REDIRECT_URL, "UTF-8")
+"&client_id="+Pokebot.config.CLIENT_ID
+"&client_secret="+Pokebot.config.CLIENT_SECRET);
request.addHeader("Content-Type", "application/x-www-form-urlencoded");
TokenResponse tokenResponse = gson.fromJson(request.execute().returnContent().asString(), TokenResponse.class);
if(tokenResponse.access_token == null){
System.err.println(tokenResponse.error);
return null;
}
return tokenResponse.access_token;
} catch(IOException e){
e.printStackTrace();
System.err.println("\nUnable to get token");
}
return null;
}
示例3: postFile
import org.apache.http.client.fluent.Request; //導入方法依賴的package包/類
/**
* 上傳文件
*
* @param url URL
* @param name 文件的post參數名稱
* @param file 上傳的文件
* @return
*/
public static String postFile(String url, String name, File file) {
try {
HttpEntity reqEntity = MultipartEntityBuilder.create().addBinaryBody(name, file).build();
Request request = Request.Post(url);
request.body(reqEntity);
HttpEntity resEntity = request.execute().returnResponse().getEntity();
return resEntity != null ? EntityUtils.toString(resEntity) : null;
} catch (Exception e) {
logger.error("postFile請求異常," + e.getMessage() + "\n post url:" + url);
e.printStackTrace();
}
return null;
}
示例4: post
import org.apache.http.client.fluent.Request; //導入方法依賴的package包/類
public static String post(KeyPair keyPair,String url,Map<String,String> query,String body) throws ApiException {
URI uri = buildUri(url,query);
if(uri == null) {
return "";
}
url = uri.toString();
log.info("post url:{}",url);
Request request = Request.Post(url);
request.bodyString(body, ContentType.parse(Constant.CONTENT_TYPE));
//request.body(new StringEntity(body,"UTF-8"));
return request(keyPair,request,Constant.METHOD_POST,query,body);
}
示例5: postFile
import org.apache.http.client.fluent.Request; //導入方法依賴的package包/類
/**
* post上傳文件
*
* @param url 請求地址
* @param file post的文件
* @param fileName post的文件名
* @return
*/
public static String postFile(String url, File file, String fileName) {
try {
HttpEntity reqEntity = MultipartEntityBuilder.create().addBinaryBody(fileName, file).build();
Request request = Request.Post(url);
request.body(reqEntity);
HttpEntity resEntity = request.execute().returnResponse().getEntity();
String res = resEntity != null ? EntityUtils.toString(resEntity, Wechatboot.charset()) : null;
logger.debug("http post : {}\n響應數據\n{}", url, res);
return res;
} catch (Exception e) {
throw new RuntimeException("post with file請求異常", e);
}
}
示例6: post
import org.apache.http.client.fluent.Request; //導入方法依賴的package包/類
private Response post(HttpRequest request) throws IOException {
Request apacheRequest = Request.Post(request.getUrl());
if (request.getBody() != null) {
ContentType ct = ContentType.create(request.getContentType().getMimeType(),
request.getContentType().getCharset());
apacheRequest.bodyString(request.getBody(), ct);
} else if (request.getBodyForm() != null) {
apacheRequest.bodyForm(buildFormBody(request.getBodyForm()));
}
prepareRequest(apacheRequest);
return apacheRequest.execute();
}
示例7: post
import org.apache.http.client.fluent.Request; //導入方法依賴的package包/類
HttpClientResponseDTO post(final HttpClientCallDTO reqDto) throws IOException {
final Request request = Request.Post(reqDto.getUrl());
handleRequestData(request, reqDto.getHeaders(), reqDto);
return executeRequest(request, reqDto.getHeaders());
}