本文整理匯總了Java中org.apache.http.client.methods.HttpPut.setHeader方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpPut.setHeader方法的具體用法?Java HttpPut.setHeader怎麽用?Java HttpPut.setHeader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.http.client.methods.HttpPut
的用法示例。
在下文中一共展示了HttpPut.setHeader方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: sendPutCommand
import org.apache.http.client.methods.HttpPut; //導入方法依賴的package包/類
/**
* sendPutCommand
*
* @param url
* @param parameters
* @return
* @throws ClientProtocolException
*/
public Map<String, Object> sendPutCommand(String url, Map<String, Object> credentials,
Map<String, String> parameters) throws ManagerResponseException {
Map<String, Object> response = new HashMap<String, Object>();
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpPut httpPut = new HttpPut(url);
httpPut.setHeader("Accept", "application/json");
httpPut.setHeader("Content-type", "application/json");
try {
ObjectMapper mapper = new ObjectMapper();
StringEntity entity = new StringEntity(mapper.writeValueAsString(parameters));
httpPut.setEntity(entity);
CloseableHttpResponse httpResponse = httpclient.execute(httpPut, localContext);
ResponseHandler<String> handler = new CustomResponseErrorHandler();
String body = handler.handleResponse(httpResponse);
response.put(BODY, body);
httpResponse.close();
} catch (Exception e) {
throw new ManagerResponseException(e.getMessage(), e);
}
return response;
}
示例2: writeA
import org.apache.http.client.methods.HttpPut; //導入方法依賴的package包/類
public boolean writeA(String key,String[] all_data) {
try {
StringBuffer sb = new StringBuffer();
sb.append("{"+QUATA+key+QUATA+":[");
for (String i : all_data) {
sb.append(QUATA+i+QUATA+",");
}
String data = sb.toString();
data = data.substring(0, data.length() - 1);
String node = data + "]}";
HttpClient httpclient = HttpClients.createDefault();
HttpPut httppost = new HttpPut(getChannelUrl()); // Use PUT prevents key generation for each as a parent
StringEntity entity = new StringEntity(node);
httppost.setEntity(entity);
httppost.setHeader("Accept", "application/json");
httppost.setHeader("Content-type", "application/json");
HttpResponse response = httpclient.execute(httppost);
this.resetChannel();
return response.getStatusLine().getStatusCode() == 200;
} catch (Exception ex) {
ex.printStackTrace();
return false;
}
}
示例3: put
import org.apache.http.client.methods.HttpPut; //導入方法依賴的package包/類
private Map put(String url, String data) throws IOException, HttpException {
Map<String,Object> map = null;
CredentialsProvider credentials = credentialsProvider();
CloseableHttpClient httpclient = HttpClients.custom()
.setDefaultCredentialsProvider(credentials)
.build();
try {
HttpPut httpPut = new HttpPut(url);
httpPut.setHeader("Accept", "application/json");
httpPut.setHeader("Content-Type", "application/json");
HttpEntity entity = new ByteArrayEntity(data.getBytes("utf-8"));
httpPut.setEntity(entity);
System.out.println("Executing request " + httpPut.getRequestLine());
CloseableHttpResponse response = httpclient.execute(httpPut);
try {
LOG.debug("----------------------------------------");
LOG.debug((String)response.getStatusLine().getReasonPhrase());
String responseBody = EntityUtils.toString(response.getEntity());
LOG.debug(responseBody);
Gson gson = new Gson();
map = new HashMap<String,Object>();
map = (Map<String,Object>) gson.fromJson(responseBody, map.getClass());
LOG.debug(responseBody);
} finally {
response.close();
}
} finally {
httpclient.close();
}
return map;
}
開發者ID:dellemc-symphony,項目名稱:ticketing-service-paqx-parent-sample,代碼行數:35,代碼來源:TicketingIntegrationService.java
示例4: sendPut
import org.apache.http.client.methods.HttpPut; //導入方法依賴的package包/類
private JsonObject sendPut(String domain, URI target, JsonObject payload) {
String authObj = getAuthObj(domain, "PUT", target, payload);
String sign = global.getSignMgr().sign(authObj);
String key = "ed25519:" + global.getKeyMgr().getCurrentIndex();
HttpPut req = new HttpPut(target);
req.setEntity(getJsonEntity(payload));
req.setHeader("Host", domain);
req.setHeader("Authorization",
"X-Matrix origin=" + global.getDomain() + ",key=\"" + key + "\",sig=\"" + sign + "\"");
log.info("Calling [{}] {}", domain, req);
try (CloseableHttpResponse res = client.execute(req)) {
int resStatus = res.getStatusLine().getStatusCode();
JsonObject body = getBody(res.getEntity());
if (resStatus == 200) {
log.info("Got answer");
return body;
} else {
throw new FederationException(resStatus, body);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}