Jump to content

Recommended Posts

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>

 

Link to comment
https://forums.phpfreaks.com/topic/301112-api-call-how-to-post-request/
Share on other sites

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);
      

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 by robc3129

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.