httprequest在Windows上的PHP5.5.38中卷曲
我希望有人能帮我。我继承了一些代码,我不知道它是如何工作的,现在它坏了,我必须修复它 我正在Windows server 2012和IIS 8.5上运行PHP 5.5.38。我终于发现php代码使用的是httprequest,这在我的php版本和windows中已经不存在了。如果可能的话,我将如何将下面的代码转换为使用curl代码httprequest在Windows上的PHP5.5.38中卷曲,php,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', Http
$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");
}
$http=newhttprequest('https://my.securelink.com/external/readi/ssoRequest,HttpRequest::METH_POST);
$http->addHeaders(
排列(
“READI_AccessKey”=>$AccessKey,
'READI_Timestamp'=>$Timestamp,
“READI_RequestSignature”=>$mac
)
);
$http->addPostFields(
排列(
'READIUsername'=>'myusername',
“LastName”=>$\u GET[“lastn”],
“FirstName”=>$\u GET[“firstn”],
'Email'=>$\u GET[“em”],
“ForceNewAssessment”=>错误,
'InternalID'=>$\u GET[“userid”],
“包括设置”=>“
)
);
//可选Post字段:“READIUserID”=>“xxxxxx”
$response=$http->send()->getBody();
回声“=======响应=====”;
回声“;
回音$应答;
回声“;
$arr=xml2array($response);
$rtn_status=getvaluebypath($arr,'sso/status');
$rtn_timestamp=getvaluebypath($arr,'sso/timestamp');
如果($rtn_状态==“成功”){
$redirectURL=getvaluebypath($arr,'sso/redirectURL');
回波“=======接入链路=====”;
回声“;
标题(“位置:$redirectURL”);
}
如果不想更改整个代码,可以尝试将HttpRequest
类添加为(来自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);