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


Java HttpPut.addHeader方法代码示例

本文整理汇总了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);
		}
	}
 
开发者ID:marklogic,项目名称:marklogic-rdf4j,代码行数:21,代码来源:ConnectedRESTQA.java

示例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;
}
 
开发者ID:ApinautenGmbH,项目名称:integration-test-helper,代码行数:28,代码来源:AomHttpClient.java

示例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);
}
 
开发者ID:JiaXiaohei,项目名称:elasticjob-stock-push,代码行数:30,代码来源:HttpUtils.java

示例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);
}
 
开发者ID:JiaXiaohei,项目名称:elasticjob-oray-client,代码行数:31,代码来源:HttpUtils.java

示例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);
	}
}
 
开发者ID:marklogic,项目名称:marklogic-rdf4j,代码行数:20,代码来源:ConnectedRESTQA.java

示例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;
}
 
开发者ID:ApinautenGmbH,项目名称:integration-test-helper,代码行数:40,代码来源:AomHttpClient.java

示例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);
	}
}
 
开发者ID:marklogic,项目名称:marklogic-rdf4j,代码行数:21,代码来源:ConnectedRESTQA.java

示例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"));
}
 
开发者ID:pjbank,项目名称:pjbank-java-sdk,代码行数:22,代码来源:ContaDigitalManager.java

示例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);
   }
 
开发者ID:linkingli,项目名称:FaceDistinguish,代码行数:30,代码来源:HttpUtils.java

示例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);
}
 
开发者ID:noesblog,项目名称:aliyunOcrSDK,代码行数:30,代码来源:HttpUtils.java

示例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;
}
 
开发者ID:ApinautenGmbH,项目名称:integration-test-helper,代码行数:33,代码来源:AomHttpClient.java

示例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;
}
 
开发者ID:funtl,项目名称:framework,代码行数:12,代码来源:HttpClientUtil.java

示例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;
	}
	
}
 
开发者ID:toni8810,项目名称:TradingRobot,代码行数:37,代码来源:Trading.java

示例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();
			}
		}
	}
 
开发者ID:marklogic,项目名称:marklogic-rdf4j,代码行数:57,代码来源:ConnectedRESTQA.java

示例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;
}
 
开发者ID:toni8810,项目名称:TradingRobot,代码行数:67,代码来源:Trading.java


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