drbe16008 2018-06-12 13:38
浏览 179

使用基本身份验证和发送json数据进行卷曲

Im using this code in my command prompt to test if i can have the authorization to send data to the given url to me.

curl --header "Authorization":"base64" -H "Content-Type: text/html; charset=UTF-8" -H "Accept: application/json" -X POST -d '{"firstname":"test","lastname":"test","mobile_number":09999999999,"education":"Bachelor's Degree","email":"test@gmail.com","job_opening_id":123}' https://www.test.com -v

but i think it cannot receive POST method datas because of this:

< HTTP/1.1 405 Method Not Allowed
< Server: nginx/1.13.12
< Content-Type: text/html; charset=UTF-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< allow: GET, HEAD
< Cache-Control: no-cache, private

the allow header has only GET and HEAD method if what i think is correct it really wont accept datas from me.

but when i only run this code:

curl --header "Authorization":"base64" https://www.test.com -v

it will run properly but i cant send datas that way. so my question is what am i doing wrong ? or if it is the allow header that is causing the problem. Thanks mates !

  • 写回答

1条回答 默认 最新

  • dqy27359 2018-06-13 01:29
    关注

    Try:

    curl -i --header "Authorization":"base64" "https://www.test.com" -G --data-urlencode json='{"firstname":"test","lastname":"test","mobile_number":09999999999,"education":"Bachelors Degree","email":"test@gmail.com","job_opening_id":123}'
    

    This returns:

    HTTP/1.1 200 OK
    Server: nginx/1.13.12
    Date: Wed, 13 Jun 2018 01:23:42 GMT
    Content-Type: text/html
    Transfer-Encoding: chunked
    Connection: keep-alive
    Keep-Alive: timeout=20
    X-DIS-Request-ID: d065c375da705938b3d3e136fc1dda23
    P3P: CP="NON DSP COR ADMa OUR IND UNI COM NAV INT"
    Cache-Control: no-cache
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta http-equiv="Content-Script-Type" content="text/javascript">
    <script type="text/javascript">
    function getCookie(c_name) { // Local function for getting a cookie value
        if (document.cookie.length > 0) {
            c_start = document.cookie.indexOf(c_name + "=");
            if (c_start!=-1) {
            c_start=c_start + c_name.length + 1;
            c_end=document.cookie.indexOf(";", c_start);
    
            if (c_end==-1)
                c_end = document.cookie.length;
    
            return unescape(document.cookie.substring(c_start,c_end));
            }
        }
        return "";
    }
    function setCookie(c_name, value, expiredays) { // Local function for setting a value of a cookie
        var exdate = new Date();
        exdate.setDate(exdate.getDate()+expiredays);
        document.cookie = c_name + "=" + escape(value) + ((expiredays==null) ? "" : ";expires=" + exdate.toGMTString()) + ";path=/";
    }
    function getHostUri() {
        var loc = document.location;
        return loc.toString();
    }
    setCookie('YPF8827340282Jdskjhfiw_928937459182JAX666', '96.93.126.65', 10);
    try {
        location.reload(true);
    } catch (err1) {
        try {
            location.reload();
        } catch (err2) {
            location.href = getHostUri();
        }
    }
    </script>
    </head>
    <body>
    <noscript>This site requires JavaScript and Cookies to be enabled. Please change your browser settings or upgrade your browser.</noscript>
    </body>
    </html>
    

    The -G flag makes all data to be used in an HTTP GET instead of POST:

    -G, --get

    When used, this option will make all data specified with -d, --data, --data-binary or --data-urlencode to be used in an HTTP GET request instead of the POST request that otherwise would be used. The data will be appended to the URL with a '?' separator.

    This post may be helpful: Curl GET with JSON parametr. Empty reply from server

    评论

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码