zoukankan      html  css  js  c++  java
  • 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";
                }
            }
  • 相关阅读:
    MyEclipse10 复制之前的项目部署到tomcat时项目名称对不上,还是复制前的项目名称,哪里修改设置
    11 The superlative
    jQuery Mobile学习笔记
    MySQL基础
    ANGULAR $HTTP请求
    Effective前端5:减少前端代码耦合
    AJAX的简介
    原生ajax
    Ionic实战 自动升级APP(Android版)
    读取数据库信息构建视图字段的备注信息,方便程序代码生成
  • 原文地址:https://www.cnblogs.com/zhao1949/p/9929518.html
Copyright © 2011-2022 走看看