-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_test.php
More file actions
45 lines (40 loc) · 1.49 KB
/
api_test.php
File metadata and controls
45 lines (40 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script type="text/javascript">
$( document ).ready(function() {
$.ajax({
url : "https://www.pronoor.com/shopping_cart/api/user/login",
type : 'post',
data : 'username=' + encodeURIComponent('admin') + '&password=' + encodeURIComponent('password'),
dataType : 'json',
error : function(data) {
console.log(data);
},
success : function(data) {
console.log(data);
}
});
});
</script>
<?php $service_url = 'https://www.pronoor.com/shopping_cart/api/user/login'; // .xml asks for xml data in response
$post_data = array(
'username' => 'admin',
'password' => 'Admin@10',
);
$post_data = http_build_query($post_data, '', '&'); // Format post data as application/x-www-form-urlencoded
// set up the request
$curl = curl_init($service_url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // have curl_exec return a string
curl_setopt($curl, CURLOPT_POST, true); // do a POST
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data); // POST this data
// make the request
curl_setopt($curl, CURLOPT_VERBOSE, true); // output to command line
$response = curl_exec($curl);
curl_close($curl);
print "RESPONSE:\n";
var_dump($response);
exit;
// parse the response
$xml = new SimpleXMLElement($response);
$session_cookie = $xml->session_name .'='. $xml->sessid;
print "SESSION_COOKIE: $session_cookie";
file_put_contents('session_cookie.txt', $session_cookie);