httpsquest在Windows上的php 5.5.38中卷曲

时间:2018-03-20 21:57:43

标签: php

我希望有人可以帮助我。我继承了一些代码,我不知道它是如何工作的,现在它已经破坏了我必须解决它。

我在Windows Server 2012和IIS 8.5上运行PHP 5.5.38。我终于发现php代码正在使用httprequest,它在我的php版本和windows中不再存在。如果可能的话,如何将以下内容转换为使用curl代码?

$http = new HttpRequest('https://my.securelink.com/external/readi/ssoRequest', HttpRequest::METH_POST);

$http->addHeaders(
    array(
        'READI_AccessKey' => $accesskey, 
        'READI_Timestamp' => $timestamp,
        'READI_RequestSignature' => $mac
    )
);

$http->addPostFields(
    array(
        'READIUsername' => 'myusername',
        'LastName' => $_GET["lastn"],
        'FirstName' => $_GET["firstn"],
        'Email' => $_GET["em"],
        'ForceNewAssessment' => false,
        'InternalID' => $_GET["userid"],
        'IncludeSettings' => ''
    )
);
//Optional Post Field:  'READIUserID' => 'xxxxxx'


$response = $http->send()->getBody();

echo "<h3>===== Response ===== </h3>";
echo "<pre>";
echo $response;
echo "</pre>";

$arr = xml2array($response);

$rtn_status = getvaluebypath($arr,'sso/status');
$rtn_timestamp = getvaluebypath($arr,'sso/timestamp');

if($rtn_status == "success") {

    $redirectURL = getvaluebypath($arr,'sso/redirectUrl');

    echo "<h3>===== Access Link ===== </h3>";
    echo "<a href=\"" . $redirectURL . "\" target=\"_blank\">" . $redirectURL . "</a>";
    header( "Location: $redirectURL");
}

1 个答案:

答案 0 :(得分:0)

如果您不想更改整个代码,可以尝试将HttpRequest类添加为https://www.example.net/test_oauth/index.php(来自 Jiri Hrazdil 评论的guyver4mk suggested)。

但是既然你问过如何将现有转换为cURL,请试试这个:

$header = [
    'READI_AccessKey: '.$accesskey,
    'READI_Timestamp: '.$timestamp,
    'READI_RequestSignature: '.$mac
];


$post = [
    'READIUsername' => 'myusername',
    'LastName' => $_GET["lastn"],
    'FirstName' => $_GET["firstn"],
    'Email' => $_GET["em"],
    'ForceNewAssessment' => false,
    'InternalID' => $_GET["userid"],
    'IncludeSettings' => ''
];

$ch = curl_init();

$options = [
    CURLOPT_URL => 'https://my.securelink.com/external/readi/ssoRequest',
    CURLOPT_HTTPHEADER => $header,
    CURLOPT_POST => 1,
    CURLOPT_POSTFIELDS => $post,
    CURLOPT_RETURNTRANSFER => 1
];

curl_setopt_array($ch, $options);

$response = curl_exec($ch);

if (!$response)
    print_r(curl_error($ch));

curl_close($ch);