OT - need help with PHP

bob gailer bgailer at gmail.com
Fri Feb 1 15:07:01 EST 2019


Thank you for your various responses.  All helpful and encouraging.

RE mailing list: I followed the instructions at 
http://php.net/manual/en/faq.mailinglist.php.

I have had no response. Shouldn't I get something either welcoming me to 
the list or requesting a confirmation?

Here are the instructions from the api vendor: (somewhat lengthy)

HOW TO CALL A FUNCTION USING VOIP.MS REST/JSON API
The following samples show how to get all Servers Information from our 
database and how to select a specific Server for your display purposes.

Please Note:
- When using our REST/JSON API you need to send the Method to be used 
and the Required Parameters as part of the URL.
- By default the output Content-Type is "text/html".
- If you want the output Content-Type to be "application/json", add the 
following to your URL: &content_type=json

PHP - Using cURL GET - Sample Code

|$ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true ); 
curl_setopt($ch, CURLOPT_URL, 
"https://voip.ms/api/v1/rest.php?api_username=john@domain.com&api_password=password&method=getServersInfo&server_pop=1"); 
$result1 = curl_exec($ch); curl_close($ch); 
$data1=json_decode($result1,true); print_r($data1);|


PHP - Using cURL POST - Sample Code

|$postfields = array( 'api_username'=>'john at domain.com', 
'api_password'=>'password', 'method'=>'getServersInfo', 
'server_pop'=>'1'); $ch = curl_init(); curl_setopt($ch, 
CURLOPT_RETURNTRANSFER, true ); curl_setopt($ch, CURLOPT_POST, true ); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); curl_setopt($ch, 
CURLOPT_URL, "https://voip.ms/api/v1/rest.php"); $result = 
curl_exec($ch); curl_close($ch); $data=json_decode($result,true); 
print_r($data); |

Note: I have edited these examples by removing unnecessary stuff, to 
make their size reasonable.

On the Python side, I can make the GET version work using 
urllib.request. I will try requests soon.

When I try to run the post example using php -r "path-to-php-progran"; 
It just prints the program.

Any attempt at converting that to POST get me a Bad Request response.

One of my needs is to upload a .wav file. The vendor requires the file 
to be encoded into base64  and the result string included in the POST 
data, which can lead to enormously long POST data. I can successfully 
use GET to send very short .wav files, but the url length limit is 
quickly reached for a reasonable length recording. Trying to use the 
POST ability that allows me to specify the file by path fails at the 
vendor side.

Apology for long post, but I don't know what to omit. Again any help is 
welcome.

-- 
Bob Gailer


---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus



More information about the Python-list mailing list