Я пытаюсь преобразовать некоторый PHP-код в ColdFusion и иметь проблемы с методом curl.Преобразование cUrl PHP-кода в coldfusion
PHP:
// Password
$clientSecret = urlencode(settings::$password);
// Information about the resource we need access for which in this case is graph.
$graphId = 'https://graph.windows.net';
$protectedResourceHostName = 'graph.windows.net';
$graphPrincipalId = urlencode($graphId);
// Information about the app
$clientPrincipalId = urlencode($appPrincipalId);
// Construct the body for the STS request
$authenticationRequestBody = 'grant_type=client_credentials&client_secret='.$clientSecret
.'&'.'resource='.$graphPrincipalId.'&'.'client_id='.$clientPrincipalId;
//Using curl to post the information to STS and get back the authentication response
$ch = curl_init();
// set url
$stsUrl = 'https://login.windows.net/'.$appTenantDomainName.'/oauth2/token?api-version=1.0';
curl_setopt($ch, CURLOPT_URL, $stsUrl);
// Get the response back as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// Mark as Post request
curl_setopt($ch, CURLOPT_POST, 1);
// Set the parameters for the request
curl_setopt($ch, CURLOPT_POSTFIELDS, $authenticationRequestBody);
// By default, HTTPS does not work with curl.
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// read the output from the post request
$output = curl_exec($ch);
// close curl resource to free up system resources
curl_close($ch);
ColdFusion Код:
<cfhttp url="#stsUrl#" method="POST" result="resultName">
<cfhttpparam type="formfield" name="grant_type" value="client_credentials">
<cfhttpparam type="formfield" name="client_secret" value="#clientSecret#">
<cfhttpparam type="formfield" name="resource" value="#graphPrincipalId#">
<cfhttpparam type="formfield" name="client_id" value="#clientPrincipalId#">
</cfhttp>
При выполнении вызова cfhttp, я получаю ошибку 400 Bad Request
.
Я что-то упустил?
Как вы устанавливаете 'authenticationRequestBody'? Можете ли вы добавить это в свой пост? Кроме того, для добавления данных для запроса типа тела должно быть 'body'. – Beginner
@Beginner: Добавлено более подробную информацию. Итак, вы считаете, что httpparams должны быть типа 'body' вместо' formfied'? –
'httpparams должно быть типа body вместо formfied?' Вы пытались добавить данные для запроса тела. Таким образом, это должно быть 'body', и вам нужно вручную установить для него заголовок content-type. Документы: [cfhttpparam] (http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7d85.html). – Beginner