gmiskos Posted March 30, 2016 Share Posted March 30, 2016 how can i make a php post request in the bellow action with api url : http://web2sms.cosmote.gr/web2sms/DCM <REQUEST Version="1.0" encoding="UTF-8"> <ACTION Name="POSTLogin" /> <PARAMETERS> <PARAM Type="String" Name="U" Value="Username" /> <PARAM Type="String" Name="P" Value="Password" /> <PARAM Type="String" Name="A" Value="WEB2SMS" /> <PARAM Type="String" Name="ACCOUNT" Value="AccountName" /> <PARAM Type="String" Name="L" Value="Language" /> </PARAMETERS> </REQUEST> Quote Link to comment https://forums.phpfreaks.com/topic/301112-api-call-how-to-post-request/ Share on other sites More sharing options...
gmiskos Posted March 30, 2016 Author Share Posted March 30, 2016 i ve tried this $params = array ( 'U' => 'the username', 'P' => 'the password', 'A' => 'WEB2SMS', 'L' => 'EL' ); $query = http_build_query ($params); // Create Http context details $contextData = array ( 'method' => 'POST', 'header' => "Connection: close\r\n". "Content-Length: ".strlen($query)."\r\n", 'content'=> $query ); // Create context resource for our request $context = stream_context_create (array ( 'http' => $contextData )); // Read page rendered as result of your POST request $result = file_get_contents ( 'http://web2sms.cosmote.gr/web2sms/DCM', // page url false, $context); Quote Link to comment https://forums.phpfreaks.com/topic/301112-api-call-how-to-post-request/#findComment-1532606 Share on other sites More sharing options...
robc3129 Posted March 30, 2016 Share Posted March 30, 2016 (edited) Have you tried CURL? I usually use CURL to make API requests. $url = ' http://web2sms.cosmote.gr/web2sms/DCM'; $fields = array( 'U' => urlencode($_POST['Username']), 'P' => urlencode($_POST['Password']), 'A' => urlencode($_POST['WEB2SMS']), 'U' => urlencode($_POST['username']), 'ACCOUNT' => urlencode($_POST['AccountName']), 'L' => urlencode($_POST['Language']) ); //Convert the data into a value URI foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } rtrim($fields_string, '&'); //open connection $ch = curl_init(); //set the url, number of POST vars, POST data curl_setopt($ch,CURLOPT_URL, $url); curl_setopt($ch,CURLOPT_POST, count($fields)); curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string); //execute post $result = curl_exec($ch); //close connection curl_close($ch); Edited March 30, 2016 by robc3129 Quote Link to comment https://forums.phpfreaks.com/topic/301112-api-call-how-to-post-request/#findComment-1532621 Share on other sites More sharing options...
Jacques1 Posted March 30, 2016 Share Posted March 30, 2016 This is an XML-based service, so you can't just send plain POST requests. You'll have to assemble an XML document in the above format, send it with cURL and then parse the XML document you get back. Also check if the service provider already offers some kind of client or library to do this. Quote Link to comment https://forums.phpfreaks.com/topic/301112-api-call-how-to-post-request/#findComment-1532622 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.