1

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 !

Gian
  • 11
  • 4

1 Answers1

0

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

pgngp
  • 1,552
  • 5
  • 16
  • 26
  • so what i thought that it cant receive data in post method is true ? because you suggest that i use -G which means -G, --get Put the post data in the URL and use GET and the allow header has only GET and HEAD methods ? – Gian Jun 13 '18 at 13:50
  • Im using POST method because the developer of the said url said that he will only receive data from post method :( – Gian Jun 13 '18 at 13:54
  • Yes, it's better to send data using the POST method. Though from your original post I thought POST wasn't allowed by the server. – pgngp Jun 13 '18 at 17:01
  • @Gian Also, you should use `-H "Content-Type: application/json"` in your curl request since you are sending data in json format. – pgngp Jun 13 '18 at 17:05
  • solved it. I think the developer had some issues on his side that he didnt said to me because my code works after he gave me an example. I think he configured the system to receive post method datas. Anyways. Thankyou so much for your help. Much appreciated mate ! – Gian Jun 13 '18 at 23:57