本文整理匯總了Java中org.apache.http.client.methods.HttpPut.addHeader方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpPut.addHeader方法的具體用法?Java HttpPut.addHeader怎麽用?Java HttpPut.addHeader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.http.client.methods.HttpPut
的用法示例。
在下文中一共展示了HttpPut.addHeader方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setDefaultUser
import org.apache.http.client.methods.HttpPut; //導入方法依賴的package包/類
public static void setDefaultUser(String usr,String restServerName) throws ClientProtocolException, IOException {
DefaultHttpClient client = new DefaultHttpClient();
client.getCredentialsProvider().setCredentials(
new AuthScope(host, 8002),
new UsernamePasswordCredentials("admin", "admin"));
String body = "{\"default-user\": \""+usr+"\"}";
HttpPut put = new HttpPut("http://"+host+":8002/manage/v2/servers/"+restServerName+"/properties?server-type=http&group-id=Default");
put.addHeader("Content-type", "application/json");
put.setEntity(new StringEntity(body));
HttpResponse response2 = client.execute(put);
HttpEntity respEntity = response2.getEntity();
if(respEntity != null){
String content = EntityUtils.toString(respEntity);
System.out.println(content);
}
}
示例2: updateModule
import org.apache.http.client.methods.HttpPut; //導入方法依賴的package包/類
/**
* Updates the module
*
* @param moduleName
* the name of the module to add
* @param objectToUpdate
* JSON containing the key/value pais to use for update
* @return request object to check status codes and return values
*/
public Response updateModule( String moduleName, JSONObject objectToUpdate )
{
HttpPut request = new HttpPut( this.yambasBase + "modules/" + moduleName );
setAuthorizationHeader( request );
request.addHeader( "x-apiomat-system", this.system.toString( ) );
request.setEntity( new StringEntity( objectToUpdate.toString( ), ContentType.APPLICATION_JSON ) );
try
{
final HttpResponse response = this.client.execute( request );
return new Response( response );
}
catch ( final IOException e )
{
e.printStackTrace( );
}
return null;
}
示例3: doPut
import org.apache.http.client.methods.HttpPut; //導入方法依賴的package包/類
/**
* Put String
* @param host
* @param path
* @param method
* @param headers
* @param querys
* @param body
* @return
* @throws Exception
*/
public static HttpResponse doPut(String host, String path, String method,
Map<String, String> headers,
Map<String, String> querys,
String body)
throws Exception {
HttpClient httpClient = wrapClient(host);
HttpPut request = new HttpPut(buildUrl(host, path, querys));
for (Map.Entry<String, String> e : headers.entrySet()) {
request.addHeader(e.getKey(), e.getValue());
}
if (StringUtils.isNotBlank(body)) {
request.setEntity(new StringEntity(body, "utf-8"));
}
return httpClient.execute(request);
}
示例4: doPut
import org.apache.http.client.methods.HttpPut; //導入方法依賴的package包/類
/**
* Put String
*
* @param host
* @param path
* @param method
* @param headers
* @param querys
* @param body
* @return
* @throws Exception
*/
public static HttpResponse doPut(String host, String path, String method,
Map<String, String> headers,
Map<String, String> querys,
String body)
throws Exception {
HttpClient httpClient = wrapClient(host);
HttpPut request = new HttpPut(buildUrl(host, path, querys));
for (Map.Entry<String, String> e : headers.entrySet()) {
request.addHeader(e.getKey(), e.getValue());
}
if (StringUtils.isNotBlank(body)) {
request.setEntity(new StringEntity(body, "utf-8"));
}
return httpClient.execute(request);
}
示例5: associateRESTServerWithDefaultUser
import org.apache.http.client.methods.HttpPut; //導入方法依賴的package包/類
public static void associateRESTServerWithDefaultUser(String restServerName,String userName,String authType)throws Exception{
DefaultHttpClient client = new DefaultHttpClient();
client.getCredentialsProvider().setCredentials(
new AuthScope(host, 8002),
new UsernamePasswordCredentials("admin", "admin"));
String body = "{ \"default-user\":\""+userName+"\",\"authentication\": \""+authType+"\",\"group-name\": \"Default\"}";
HttpPut put = new HttpPut("http://"+host+":8002/manage/v2/servers/"+restServerName+"/properties?server-type=http");
put.addHeader("Content-type", "application/json");
put.setEntity(new StringEntity(body));
HttpResponse response2 = client.execute(put);
HttpEntity respEntity = response2.getEntity();
if(respEntity != null){
String content = EntityUtils.toString(respEntity);
System.out.println(content);
}
}
示例6: updateConfig
import org.apache.http.client.methods.HttpPut; //導入方法依賴的package包/類
/**
* Updates a modules config for the given app
*
* @param customerName
* the name of the customer
* @param appName
* the name of the app
* @param moduleName
* the name of the module to update config for
* @param key
* config key
* @param value
* value of the config
* @return request object to check status codes and return values
*/
public Response updateConfig( String customerName, String appName, String moduleName, String key,
String value )
{
final HttpPut request = new HttpPut( this.yambasBase + "customers/" + customerName + "/apps/" + appName );
setAuthorizationHeader( request );
request.addHeader( "ContentType", "application/json" );
request.addHeader( "x-apiomat-system", this.system.toString( ) );
try
{
final HttpEntity requestEntity = new StringEntity(
"{\"configuration\":" + " {\"" + this.system.toString( ).toLowerCase( ) + "Config\": {\"" +
moduleName + "\":{\"" + key + "\":\"" + value + "\"}}}, \"applicationName\":\"" + appName + "\"}",
ContentType.APPLICATION_JSON );
request.setEntity( requestEntity );
final HttpResponse response = this.client.execute( request );
return new Response( response );
}
catch ( final IOException e )
{
e.printStackTrace( );
}
return null;
}
示例7: setAuthentication
import org.apache.http.client.methods.HttpPut; //導入方法依賴的package包/類
public static void setAuthentication(String level,String restServerName) throws ClientProtocolException, IOException
{
DefaultHttpClient client = new DefaultHttpClient();
client.getCredentialsProvider().setCredentials(
new AuthScope(host, 8002),
new UsernamePasswordCredentials("admin", "admin"));
String body = "{\"authentication\": \""+level+"\"}";
HttpPut put = new HttpPut("http://"+host+":8002/manage/v2/servers/"+restServerName+"/properties?server-type=http&group-id=Default");
put.addHeader("Content-type", "application/json");
put.setEntity(new StringEntity(body));
HttpResponse response2 = client.execute(put);
HttpEntity respEntity = response2.getEntity();
if(respEntity != null){
String content = EntityUtils.toString(respEntity);
System.out.println(content);
}
}
示例8: manageWebhookURL
import org.apache.http.client.methods.HttpPut; //導入方法依賴的package包/類
/**
* Realiza a adição ou edição da URL que deve ser utilizada pelos webhooks da Conta Digital
* @param url: URL à ser configurada como Webhook
* @return boolean
*/
public boolean manageWebhookURL(String url) throws IOException, PJBankException {
PJBankClient client = new PJBankClient(this.endPoint);
HttpPut httpPut = client.getHttpPutClient();
httpPut.addHeader("x-chave-conta", this.chave);
JSONObject params = new JSONObject();
params.put("webhook", url);
httpPut.setEntity(new StringEntity(params.toString(), StandardCharsets.UTF_8));
String response = EntityUtils.toString(client.doRequest(httpPut).getEntity());
JSONObject responseObject = new JSONObject(response);
return url.equals(responseObject.getString("webhook"));
}
示例9: doPut
import org.apache.http.client.methods.HttpPut; //導入方法依賴的package包/類
/**
* Put String
* @param host
* @param path
* @param method
* @param headers
* @param querys
* @param body
* @return
* @throws Exception
*/
public static HttpResponse doPut(String host, String path, String method,
Map<String, String> headers,
Map<String, String> querys,
String body)
throws Exception {
HttpClient httpClient = wrapClient(host);
HttpPut request = new HttpPut(buildUrl(host, path, querys));
for (Map.Entry<String, String> e : headers.entrySet()) {
request.addHeader(e.getKey(), e.getValue());
}
if (StringUtils.isNotBlank(body)) {
request.setEntity(new StringEntity(body, "utf-8"));
}
return httpClient.execute(request);
}
示例10: doPut
import org.apache.http.client.methods.HttpPut; //導入方法依賴的package包/類
/**
* Put stream
* @param host
* @param path
* @param method
* @param headers
* @param querys
* @param body
* @return
* @throws Exception
*/
public static HttpResponse doPut(String host, String path, String method,
Map<String, String> headers,
Map<String, String> querys,
byte[] body)
throws Exception {
HttpClient httpClient = wrapClient(host);
HttpPut request = new HttpPut(buildUrl(host, path, querys));
for (Map.Entry<String, String> e : headers.entrySet()) {
request.addHeader(e.getKey(), e.getValue());
}
if (body != null) {
request.setEntity(new ByteArrayEntity(body));
}
return httpClient.execute(request);
}
示例11: deployApp
import org.apache.http.client.methods.HttpPut; //導入方法依賴的package包/類
/**
* Sets the app to active state
*
* @param customerName
* the name of the customer
* @param appName
* the name of the app
* @return request object to check status codes and return values
*/
public Response deployApp( String customerName, String appName )
{
HttpPut request = new HttpPut( this.yambasBase + "customers/" + customerName + "/apps/" + appName );
setAuthorizationHeader( request );
request.addHeader( "ContentType", "application/json" );
request.addHeader( "x-apiomat-system", this.system.toString( ) );
try
{
final HttpEntity requestEntity = new StringEntity(
"{\"applicationStatus\":{\"" + this.system + "\":\"ACTIVE\"}, \"applicationName\":\"" +
appName + "\"}",
ContentType.APPLICATION_JSON );
request.setEntity( requestEntity );
final HttpResponse response = this.client.execute( request );
return new Response( response );
}
catch ( final IOException e )
{
e.printStackTrace( );
}
return null;
}
示例12: createPut
import org.apache.http.client.methods.HttpPut; //導入方法依賴的package包/類
public HttpPut createPut(String url, final List<NameValuePair> params, ApplicationType accept) throws IOException {
HttpPut method = new HttpPut(url);
if (params != null) {
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, reqCharset);
method.setEntity(entity);
}
if (null != accept) {
method.addHeader("accept", accept.val());
}
return method;
}
示例13: closeExistingTrade
import org.apache.http.client.methods.HttpPut; //導入方法依賴的package包/類
private int closeExistingTrade(String buyOrSell) {
Trade t = getTrade();
long existingTradeId;
if (t != null) {
if (t.getBuyOrSell().contentEquals(buyOrSell)) return 1;
existingTradeId = t.getId();
}
else {
//No trade is open
return 0;
}
HttpClientBuilder hcb = HttpClientBuilder.create();
HttpClient client = hcb.build();
HttpPut request = new HttpPut(RequestURI.baseURL+"/v3/accounts/"+RequestURI.accountId+"/trades/"+existingTradeId+"/close");
request.addHeader(RequestURI.headerTitle,RequestURI.accessToken);
System.out.println(request.getURI());
try {
HttpResponse response = client.execute(request);
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuffer result = new StringBuffer();
String line = "";
while ((line = rd.readLine()) != null) {
result.append(line);
}
JSONObject resultJson = new JSONObject(result.toString());
System.out.println(resultJson);
return response.getStatusLine().getStatusCode();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return 0;
}
}
示例14: setDatabaseFieldProperties
import org.apache.http.client.methods.HttpPut; //導入方法依賴的package包/類
public static void setDatabaseFieldProperties(String dbName,String field_name, String propName, ObjectNode objNode ) throws IOException{
InputStream jsonstream=null;
try{
DefaultHttpClient client = new DefaultHttpClient();
client.getCredentialsProvider().setCredentials(
new AuthScope(host, 8002),
new UsernamePasswordCredentials("admin", "admin"));
HttpGet getrequest = new HttpGet("http://"+host+":8002"+ "/manage/v2/databases/"+dbName+"/properties?format=json");
HttpResponse response1 = client.execute(getrequest);
jsonstream =response1.getEntity().getContent();
ObjectMapper mapper = new ObjectMapper();
JsonNode jnode= mapper.readTree(jsonstream);
if(!jnode.isNull()&& jnode.has("field")){
JsonNode fieldNode = jnode.withArray("field");
Iterator<JsonNode> fnode = fieldNode.elements();
while(fnode.hasNext()) {
JsonNode fnchild =fnode.next();
if((fnchild.path("field-name").asText()).equals(field_name)){
// System.out.println("Hurray" +fnchild.has(propName));
if(!fnchild.has(propName)){
((ObjectNode)fnchild).putArray(propName).addAll(objNode.withArray(propName));
// System.out.println("Adding child array include node" + jnode.toString());
}
else{
JsonNode member = fnchild.withArray(propName);
((ArrayNode)member).addAll(objNode.withArray(propName));
}
}
}
HttpPut put = new HttpPut("http://"+host+":8002"+ "/manage/v2/databases/"+dbName+"/properties?format=json");
put.addHeader("Content-type", "application/json");
put.setEntity(new StringEntity(jnode.toString()));
HttpResponse response2 = client.execute(put);
HttpEntity respEntity = response2.getEntity();
if(respEntity != null){
String content = EntityUtils.toString(respEntity);
System.out.println(content);
}
}
else{
System.out.println("REST call for database properties returned NULL \n"+jnode.toString()+"\n"+ response1.getStatusLine().getStatusCode());
}
}catch (Exception e) {
// writing error to Log
e.printStackTrace();
}
finally{
if(jsonstream == null){}
else{
jsonstream.close();
}
}
}
示例15: setTakeProfitPrice
import org.apache.http.client.methods.HttpPut; //導入方法依賴的package包/類
public int setTakeProfitPrice(double lossAmmount, int numOfUnits, boolean buy) {
Trade t = getTrade();
double takeProfitPrice = t.getOpeningPrice();
double usdGbp = getUsdGbp();
double profitNeeded;
double distanceBetweenOpenPriceAndTakeProfit = 0;
if (lossAmmount < 0) {
//get the absolute value of the loss amount
profitNeeded = Math.abs(lossAmmount);
//add 5%
profitNeeded += profitNeeded * 0.05;
//add �1
profitNeeded += 1.0;
}
else {
profitNeeded = 1-lossAmmount;
}
for (double i=0.00001; i<Double.MAX_VALUE; i += 0.00001) {
if (i*usdGbp*numOfUnits >= profitNeeded) {
distanceBetweenOpenPriceAndTakeProfit = i;
break;
}
}
if (buy) takeProfitPrice += distanceBetweenOpenPriceAndTakeProfit;
else takeProfitPrice -= distanceBetweenOpenPriceAndTakeProfit;
takeProfitPrice = round(takeProfitPrice, 5);
//Modifying Trade
HttpClientBuilder hcb = HttpClientBuilder.create();
HttpClient client = hcb.build();
HttpPut request = new HttpPut(RequestURI.baseURL+"/v3/accounts/"+RequestURI.accountId+"/trades/"+t.getId()+"/orders");
request.addHeader(RequestURI.headerTitle,RequestURI.accessToken);
request.addHeader("Content-Type", "application/json");
JSONObject takeProfitObject = new JSONObject();
JSONObject takeProfitDetailsObject = new JSONObject();
takeProfitDetailsObject.put("price", String.valueOf(takeProfitPrice));
takeProfitDetailsObject.put("timeInForce", "GTC");
takeProfitObject.put("takeProfit", takeProfitDetailsObject);
System.out.println("Take Profit Price: "+takeProfitPrice);
try {
HttpEntity entity = new StringEntity(takeProfitObject.toString());
request.setEntity(entity);
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
HttpResponse response = client.execute(request);
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuffer result = new StringBuffer();
String line = "";
while ((line = rd.readLine()) != null) {
result.append(line);
}
JSONObject resultJson = new JSONObject(result.toString());
System.out.println(resultJson);
return response.getStatusLine().getStatusCode();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return 0;
}