I need some help with ExternalResourceClient with multipart/form-data? I tried following the examples at https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_12.0/Integration/ExternalResourceClient/ but they don't handle multiipart/form-data.
I need to convert this CURL
$curl_post_data = [ 'input' => $input, 'scriptName' => $scriptName ]; curl_setopt_array($curl, array( CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 3, CURLOPT_TIMEOUT => 10, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => $curl_post_data, CURLOPT_USERPWD => $credentials, )); $response = curl_exec($curl);
When this gets sent to the server the POST variables are sent as Content-Type: multipart/form-data;
The issue I have with the ExternalResourceClient is that expects the Content-Type to be application/x-www-form-urlencoded which the application does not accept.
How do I add a boundary to the $curl_post_data?
$erc = new \Sugarcrm\Sugarcrm\Security\HttpClient\ExternalResourceClient();
$boundary = '--------------------------'.microtime(true);
$curl_post_data = [
'input' => $input,
'scriptName' => $scriptName
];
$response = $erc->post($url, $curl_post_data, [
'Content-Type' => "multipart/form-data; boundary=$boundary",
'Authorization' => 'Basic '. base64_encode($credentials),
'Accept' => '*/*'
]);
//How do I add boundary to the $curl_post_data?