/* An Example XML Request */
string xmlRequest = '' ;
/* An Example JSON Request */
$jsonRequest = '' ;
$resCurl = curl_init();
curl_setopt( $resCurl, CURLOPT_POST, true );
curl_setopt( $resCurl, CURLOPT_URL, REPLACE THIS WITH THE WEB SERVICE URL );
curl_setopt( $resCurl, CURLOPT_RETURNTRANSFER, 1 );
$strFirstFileName = '<filename with path>';
$strSecondFileName = '<filename with path>';
if( true == function_exists( 'curl_file_create' ) ) {
$strFirsFilePath = curl_file_create( $strFirstFileName );
$strSecondFilePath = curl_file_create( $strSecondFileName );
} else {
$strFirsFilePath = '@' . realpath( $strFirstFileName );
$strSecondFilePath = '@' . realpath( $strSecondFileName );
}
/* If you want to send an XML Request, use these options */
$arrmixPost = [ 'requestContentType' => 'APPLICATION/XML; CHARSET=UTF-8', 'requestBody' => $xmlRequest, 'file1' => $strFirsFilePath, 'file2' => $strSecondFilePath ];
/* If you want to send a JSON Request, use these options */
$arrmixPost = [ 'requestContentType' => 'APPLICATION/JSON; CHARSET=UTF-8', 'requestBody' => $jsonRequest, 'file1' => $strFirsFilePath, 'file2' => $strSecondFilePath ];
curl_setopt( $resCurl, CURLOPT_HTTPHEADER, array( 'Content-type: multipart/form-data', 'Authorization: Basic <BASE64 ENCODED VALUE OF USERNAME:PASSWORD>' ) );
curl_setopt( $resCurl, CURLOPT_POSTFIELDS, $arrmixPost );
$result = curl_exec( $resCurl );
if( false === $result ) {
echo 'Curl error: ' . curl_error( $resCurl );
curl_close( $resCurl );
} else {
curl_close( $resCurl );
echo $result;
}