POST Multiple POST Values

  //Setup the POST fields
  $PostData = array(
    'my_field1' => $my_field1,
    'my_field1' => $my_field1
  );
  $PostData = http_build_query($PostData);
  
  $SendUrl = 'https://urltosendto.com';
  
	if(function_exists('curl_init') && function_exists('curl_setopt') && function_exists('curl_exec'))
  {
		$ch =  curl_init();
      curl_setopt($ch, CURLOPT_URL, $SendUrl);
			curl_setopt($ch, CURLOPT_POST, 1);
			curl_setopt($ch, CURLOPT_POSTFIELDS, $PostData);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);			//Connect timeout in secs
			curl_setopt($ch, CURLOPT_TIMEOUT, 10);				//Maximum time the request is allowed to take in secs
			$Response = curl_exec($ch);
		curl_close($ch);
	}

  if (strpos($Response, 'SUCCESS') !== False)
  {
    //It worked
  }

POST a json block with authorisation

  $PostData = "    {
      \"messages\":[
          {
              \"source\":\"php\",
              \"body\":\"$MessageBody\",
              \"to\":\"$DestinationTelephoneNumber\",
              \"from\":\"" . LOGIN_SMS_OUR_TELEPHONE_NUMBER . "\"
          }
      ]
  }";
  
  $SendUrl = 'https://urltosendto.com';
  $Username = 'myusername';
  $Password = 'mypassword';
  
	if(function_exists('curl_init') && function_exists('curl_setopt') && function_exists('curl_exec'))
  {
		$ch =  curl_init();
      curl_setopt($ch, CURLOPT_URL, $SendUrl);
			curl_setopt($ch, CURLOPT_POST, 1);
			curl_setopt($ch, CURLOPT_POSTFIELDS, $PostData);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
			curl_setopt($ch, CURLOPT_TIMEOUT, 10);
			curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Basic ' . base64_encode("$Username:$Password"), 'Content-Type: application/json'));
			$Response = curl_exec($ch);
		curl_close($ch);
	}

  //response_code":"SUCCESS"
  $Response = json_decode($Response, TRUE);
  $response_code = $Response['response_code'];
  
  if ($response_code == "SUCCESS")
  {
    
  }
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published.