1

is it possible to get result (see below image) using curl for this site example: http://poslaju.com.my/track-trace/#trackingIds=EP024922993MY

here is my code so far, not working:

/*$params = array(
"trackingIds" => "EP024922993MY"
);*/

$url = rawurlencode("http://poslaju.com.my/track-trace/#trackingIds=EP024922993MY");

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_POST, 1);
//curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$reponse = curl_getinfo($ch);

curl_close($ch);

var_dump($result);
var_dump($reponse);

enter image description here

1 Answer 1

1

The very first: I'm using Firebug add-on and see what happen

enter image description here Here one ajax get content from other site

We have this link

https://apis.pos.com.my/apigateway/as2corporate/api/v2trackntracewebapijson/v1/?id=EP024922993MY&Culture=En

In request of header we can see require X-User-Key

enter image description here

Now we must find X-User-Key => We can view source

enter image description here

Now we build source code

<?php
function _curl($url,$post="",$usecookie = false,$_sock = false,$timeout = false,$x_user_key = false) {  
    $ch = curl_init();
    if($post) {
        curl_setopt($ch, CURLOPT_POST ,1);
        curl_setopt ($ch, CURLOPT_POSTFIELDS, $post);
    }
    if($timeout){
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,$timeout);
    }
    if($_sock){
            curl_setopt($ch, CURLOPT_PROXY, $_sock);
            curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
    }
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16");
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'X-Apple-Tz: 0',
    'X-Apple-Store-Front: 143444,12'
    ));
    if($x_user_key){
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'X-User-Key: '.$x_user_key,
        'Referer: http://poslaju.com.my/track-trace/',
        'Origin: http://poslaju.com.my'
        ));
    }
    if ($usecookie) { 
        curl_setopt($ch, CURLOPT_COOKIEJAR, $usecookie); 
        curl_setopt($ch, CURLOPT_COOKIEFILE, $usecookie);    
    }
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 
    $result=curl_exec ($ch); 
    curl_close ($ch); 
    return $result; 
}
function getStr($string,$start,$end){
    $str = explode($start,$string,2);
    $str = explode($end,$str[1],2);
    return $str[0];
}
$url = 'http://poslaju.com.my/track-trace/';
$result_curl = _curl($url,'','','','','');
$x_user_key = getStr($result_curl,'{ "X-User-Key": "','" }');

$id_track = 'EP024922993MY';
$url = 'https://apis.pos.com.my/apigateway/as2corporate/api/v2trackntracewebapijson/v1/?id='.$id_track.'&Culture=En';
$result_curl = _curl($url,'','','','',$x_user_key);
echo $result_curl;
?>

Change id on your mind

You can get json content

Use print_r(json_decode($content_you_got)

And result you will have like this

enter image description here

Sign up to request clarification or add additional context in comments.

9 Comments

You should explain how you found that endpoint so that the person asking the question learns how to find it themselves in the future.
I'm updating my answer.
sorry, still didn't get it. return null result
Yes, exactly. I'm updating how to get X-User-Key for authenticate with this site xD
result: string(21) "Bad secret key found."
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.