Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there
I have gotten it right to pull info from soap - wsdl but cant get it formatted to import into mysql

https://fleet11.cartrack.co.za/api/[^]

What I have tried:

PHP
<pre>       $dataFromTheForm = $_POST['fieldName']; 
        $soapUrl = "https://mysite/api/"; 
        $soapUser = "AJCP00001";  //  username
        $soapPassword = "BAKKIE#001"; // password
        $xml_post_string = 
		'<?xml version="1.0" encoding="utf-8"?>
                            <soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:api="mysite/api/">
   <soapenv:Header/>
   <soapenv:Body>
      <api:endpoint.get_all_vehicles_last_positions soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
         <user_name xsi:type="xsd:string">?</user_name>
         <registration xsi:type="xsd:string">?</registration>
      </api:endpoint.get_all_vehicles_last_positions>
   </soapenv:Body>
</soapenv:Envelope> ';   

           $headers = array(
                        "Content-type: application/x-www-form-urlencoded",
                        "Accept: text/xml",
                        "Cache-Control: no-cache",
                        "Pragma: no-cache",
                        "SOAPAction: mysite/api/#get_vehicle_list_all_details", 
		
                        "Content-length: ".strlen($xml_post_string),
                    ); 
           $url = $soapUrl;
             $ch = curl_init();
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_USERPWD, $soapUser.":".$soapPassword); 
            curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
            curl_setopt($ch, CURLOPT_TIMEOUT, 10);
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); 
            curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
			curl_setopt($ch, CURLOPT_HEADER, true); 

            $response = curl_exec($ch); 
            curl_close($ch);
print_r(explode(',',$response,-1));


and response

Quote:
Array ( [0] => HTTP/1.1 401 Unauthorized Date: Fri [1] => 17 Jul 2020 13:50:23 GMT Server: Apache WWW-Authenticate: Basic realm="Authentification" Vary: Accept-Encoding [2] => User-Agent Access-Control-Allow-Origin: * Access-Control-Allow-Methods: POST [3] => GET [4] => OPTIONS Access-Control-Allow-Headers: Origin [5] => X-Requested-With [6] => Content-Type [7] => Accept Access-Control-Allow-Credentials: true Content-Length: 2221 Content-Type: text/html HTTP/1.1 200 OK Date: Fri [8] => 17 Jul 2020 13:50:23 GMT Server: Apache X-SOAP-Server: NuSOAP/0.9.5 (1.123) Content-Length: 13744 Vary: Accept-Encoding [9] => User-Agent Access-Control-Allow-Origin: * Access-Control-Allow-Methods: POST [10] => GET [11] => OPTIONS Access-Control-Allow-Headers: Origin [12] => X-Requested-With [13] => Content-Type [14] => Accept Access-Control-Allow-Credentials: true Content-Type: text/xml; charset=UTF-8 131928943CM63CKGP2020-07-17 15:50:01+02-26.10796228.14736512031M54 [15] => Lakeside [16] => Kempton Park [17] => Gauteng [18] => South Africa128390376131929103CW94GBGP2020-07-17 15:49:29+02-26.15745528.16410532354Van Riebeeck Avenue [19] => Meadowbrook [20] => Germiston [21] => Gauteng [22] => South Africa91855236131929189DJ17CSGP2020-07-17 15:33:23+02-26.13019728.1595951220Lucas Road [23] => Eastleigh [24] => Edenvale [25] => Gauteng [26] => South Africa134415550131644752DZ04YCGP2020-07-16 22:17:37+02-26.12998428.1621971010Central Avenue [27] => Eastleigh [28] => Edenvale [29] => Gauteng [30] => South Africa100380393174261628FF98ZWGP2020-07-17 14:51:34+02-26.0383828.0489632840Western Bypass [31] => Bryanston [32] => Sandton [33] => Gauteng [34] => South Africa111391551176362877FJ14LJGP2020-07-17 15:25:25+02-26.13020528.1596271260Lucas Road [35] => Eastleigh [36] => Edenvale [37] => Gauteng [38] => South Africa86783525174262077FX50RTGP2020-07-17 15:49:46+02-26.11773328.145104120Greenstone Park [39] => Kempton Park [40] => Gauteng [41] => South Africa108650021115687485HG07DKGP2020-07-17 15:08:42+02-26.13025728.159412730Lucas Road [42] => Eastleigh [43] => Edenvale [44] => Gauteng [45] => South Africa54697248115687333HG07DPGP2020-07-17 15:49:58+02-26.1302928.159395180Diaz Avenue [46] => Eastleigh [47] => Edenvale [48] => Gauteng [49] => South Africa26220109116851782HH65MRGP2020-07-17 15:41:42+02-26.19483928.2277072460Boksburg [50] => Gauteng [51] => South Africa36314333124523364HL98BLGP2020-07-17 15:22:06+02-26.13027528.159397830Lucas Road [52] => Eastleigh [53] => Edenvale [54] => Gauteng [55] => South Africa42238135124523243HM02SRGP2020-07-17 08:06:36+02-25.75988128.3796093140Close to Mamelodi [56] => Gauteng [57] => South Africa74083776133862270HR66YXGP2020-07-17 15:38:36+02-29.52169631.2085222600Ballito [58] => KwaZulu-Natal [59] => South Africa67201535146454559HV78BLGP2020-07-17 14:01:24+02-26.1300728.159572440Lucas Road [60] => Eastleigh [61] => Edenvale [62] => Gauteng [63] => South Africa31580999152773681HX90JJGP2020-07-17 15:49:32+02-25.96879428.009977527Riverglen [64] => Randburg [65] => Gauteng [66] => South Africa17057893167023369HZ14SDGP2020-07-17 13:41:07+02-26.13027428.159632460Lucas Road [67] => Eastleigh [68] => Edenvale [69] => Gauteng [70] => South Africa19311645159833291JB31BYGP2020-07-17 15:08:48+02-26.1302428.1592752490Lucas Road [71] => Eastleigh [72] => Edenvale [73] => Gauteng [74] => South Africa32396495174261922JG94XXGP2020-07-17 15:49:57+02-26.12901528.21214994119Albertina Sisulu Freeway [75] => Spartan [76] => Kempton Park [77] => Gauteng [78] => South Africa26695273167435050JH04HZGP2020-07-17 12:52:13+02-26.0638128.18506433973Zuurfontein Avenue [79] => Chloorkop [80] => Kempton Park [81] => Gauteng )
Posted
Updated 19-Jul-20 2:09am

1 solution

Based on the error, it seems the case of Authorization issue. Whatever authenticated user (username + passwrod) you are using to talk to the service seems not authorized to interact.

Make sure:
1. You have a right user who is authorized to access the service
2. You pass on the details of the authenticated user along with your request to service.

Thanks!
 
Share this answer
 
Comments
Paul van Zyl 20-Jul-20 2:06am    
Your answer is incorrect, if it was wrong user i would not have been able to return data that needs to be exploded
Sandeep Mewara 20-Jul-20 3:42am    
Okies, no issue. Thanks for sharing. Not sure how you get data when its a 401 error from a service.



This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900