【问题标题】:httprequest to curl in php 5.5.38 on Windowshttprequest 在 Windows 上的 php 5.5.38 中卷曲
【发布时间】:2018-03-20 21:57:42
【问题描述】:

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

我在 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");
}

【问题讨论】:

标签: php


【解决方案1】:

如果您不想更改整个代码,可以尝试将HttpRequest 类添加为guyver4mk suggestedthe link 来自Jiri Hrazdil 的 评论)。

但既然你问如何将现有的转换为 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);

【讨论】:

    猜你喜欢
    • 2012-03-12
    • 2016-04-27
    • 2017-02-05
    • 2012-08-31
    • 1970-01-01
    • 2016-03-14
    • 2018-02-23
    • 1970-01-01
    • 2015-06-03
    相关资源
    最近更新 更多