curl命令例解

curl -i --url "https://open.abc.com/ddn/purge/ItemIdReceiver" \
-X "POST" \
-u "$username:$password" \
-H "Date:$date" \
-H "Content-Type: application/json" \
-d'{
    "urls": [
        "https://www.abc.com/test/test1.txt",
        "https://www.abc.com/test/test2.txt"
            ],
 "urlAction":"delete",
    "dirs": [
        "https://www.abc.com/test/",
        "https://www.abc.com/test2/"
            ],
 "dirAction":"expire",
}'

 

-u 等同于header Authorization:Basic username:password的base64编码.

-d post json 字串.

	try(CloseableHttpClient httpClient = HttpClients.createDefault() ) {
            HttpPost httpPost = new HttpPost("https://open.abc.com/ddn/purge/ItemIdReceiver");
            
            httpPost.addHeader("Content-Type", "application/json");
			//rfc1123
            SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z",Locale.US);
        	sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
        	String dateStr = sdf.format(new Date());

        	
            httpPost.addHeader("Date", dateStr);
            
            //加密
            final Base64 base64 = new Base64();
            String password = base64.encodeToString( HmacSHA1Encrypt(dateStr, key) );
            String basicAuth = base64.encodeToString( (username+ ":" + password).getBytes("utf-8") );
            
            httpPost.addHeader("Authorization", "Basic " + basicAuth);
            
            httpPost.setEntity(new StringEntity(bodyJsonStr) );
            
            HttpResponse response = httpClient.execute(httpPost);// 执行提交
            if(response.getStatusLine().getStatusCode() != 200) {
            	return "error";
            }
            
            HttpEntity responseEntity = response.getEntity();
            if (responseEntity != null) {
                // 将响应内容转换为字符串
                reponseStr = EntityUtils.toString(responseEntity, "utf-8");
                logger.info(trans + ",response=" + reponseStr);
                
    			return "success";
            }
	}

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值