将cURL命令转换为PHP cURL(SSL) 我跑
这个卷曲在我的终端的命令行中将cURL命令转换为PHP cURL(SSL) 我跑,php,apache,ssl,curl,https,Php,Apache,Ssl,Curl,Https,这个卷曲在我的终端的命令行中 curl-c会话_cookies.txt”https://login.uat.site.be/openid/oauth/authorize?client_id=site&state=e1968018-bb04-4475-86fa-b0728e9fb038&nonce=f7b76b29-2c42-423d-8d1c-5b1d0a8ce8bf&response_type=code&claims=%7B%22id_令牌%22%3A%7B%22http%3A%2F%2F站点
curl-c会话_cookies.txt”https://login.uat.site.be/openid/oauth/authorize?client_id=site&state=e1968018-bb04-4475-86fa-b0728e9fb038&nonce=f7b76b29-2c42-423d-8d1c-5b1d0a8ce8bf&response_type=code&claims=%7B%22id_令牌%22%3A%7B%22http%3A%2F%2F站点。be%2FSclaims%2Roles%22%3Anull%7D“2>/dev/null | curl-v-b session|cookies.txt-L-H“内容类型:application/x-www-form-urlencoded”-v-d'j_username=manager-sitelogin@gmail.com&j_密码=123'”https://login.uat.site.be/openid/login.do“2>&1>/dev/null | grep Location | grep code=
我得到了
这是我的回应
<位置:https://testserver.sitenets.com/user/secure/dashboard?code=4z71kBZ4iYlqfDB7qOHvZgyXkqVEaL7v&state=e1968018-bb04-4475-86fa-b0728e9fb038
注
code=4z71kBZ4iYlqfDB7qOHvZgyXkqVEaL7v
这就是我想要的
然后 我已经尝试将curl命令行转换为PHP curl
$ch = curl_init( 'https://login.uat.site.be/openid/oauth/authorize' );
curl_setopt($ch, CURLOPT_POST, true );
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'client_id' => 'site',
'state' => $state,
'nonce' => $nonce,
'claims' => '%7B%22id_token%22%3A%7B%22http%3A%2F%2Fsite.be%2Fclaims%2Froles%22%3Anull%7D%7D',
'response_type' => 'code'
) );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, public_path().'/session_cookies.txt');
curl_setopt($ch, CURLOPT_VERBOSE, true);
$first_curl = curl_exec($ch);
$cookie_file = public_path(). '/session_cookies.txt';
if (file_exists($cookie_file)) {
$pem_file_path = '/Applications/MAMP/conf/apache/openid.site.com.cert.pem';
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_CAINFO=> $pem_file_path,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query(array(
'j_username' => urlencode($un),
'j_password' => $pw,
)),
CURLOPT_COOKIEJAR => $cookie_file,
CURLOPT_COOKIEFILE => $cookie_file,
);
$ch = curl_init();
curl_setopt_array($ch, $options);
curl_setopt($ch, CURLOPT_URL, 'https://login.uat.site.be/openid/login.do');
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
dd($result);
}
我从来没有得到与在终端上执行该命令相同的结果
当我从dd
中取出$result
变量时,我的浏览器上不断出现这些垃圾信息
"""
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->\r\n
<!DOCTYPE html>\r\n
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->\r\n
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->\r\n
<!--[if gt IE 8]><!-->\r\n
<html class="no-js">\r\n
<!--<![endif]-->\r\n
<head>\r\n
<title>site: Meld je aan</title>\r\n
<meta content="IE=edge" http-equiv="X-UA-Compatible">\r\n
<meta charset="utf-8">\r\n
<meta content="width=device-width, initial-scale=1, maximum-scale=1" name="viewport">\r\n
<meta name="description" content="">\r\n
\r\n
<link rel="shortcut icon" href="//static.site.be/assets/favicon/favicon.ico" type="image/x-icon"/>\r\n
<link rel="stylesheet" href="css/vendor/normalize.min.css">\r\n
<link rel="stylesheet" href="css/login.css">\r\n
<link rel="stylesheet" type="text/css" href="//static.site.be/assets/fonts/omnes-breuer-logo/stylesheet.css">\r\n
\r\n
<link rel="stylesheet" href="https://static.uat.site.be/oauth2/css/main.css">\r\n
\r\n
<!-- Adobe analytics -->\r\n
<script src="https://www2.site.be/etc/designs/site-be/js/statistics/SiteCatalyst.js"></script>\r\n
\r\n
<script type="text/javascript">\r\n
function hideHtmlElement(id) {\r\n
document.getElementById(id).style.display = "none";\r\n
}\r\n
\r\n
function showHtmlElement(id) {\r\n
document.getElementById(id).style.display = "block";\r\n
}\r\n
\r\n
function showPanel(id) {\r\n
hideHtmlElement("forgotLogin");\r\n
hideHtmlElement("showLogin");\r\n
hideHtmlElement("forgotPassword");\r\n
showHtmlElement(id);\r\n
}\r\n
\r\n
</script>\r\n
\r\n
<!--[if lt IE 9]>\r\n
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>\r\n
<![endif]-->\r\n
</head>\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
<div class="wrapper">\r\n
<span id="showBackgroundForStatic" style="display: none">true</span>\r\n
<!-- ERROR SCREEN -->\r\n
<div class="container">\r\n
<div id="loginContainer">\r\n
<div id="showLogin">\r\n
<div class="options clearfix">\r\n
<div class="option-sites">\r\n
<ul>\r\n
<li><a target="_blank"\r\n
href="http://site.be/nl">Meer site</a></li>\r\n
<li><a target="_blank" href="http://site.be/nl"\r\n
tabindex="-1">site.be</a></li>\r\n
<li><a target="_blank" href="http://business.site.be/"\r\n
tabindex="-1">Business</a></li>\r\n
<li><a target="_blank"\r\n
href="http://corporate.site.be/" tabindex="-1">Over site</a></li>\r\n
<li><a target="_blank"\r\n
href="http://klantenservice.site.be/"\r\n
tabindex="-1">Klantenservice</a></li>\r\n
</ul>\r\n
</div>\r\n
<div class="option-language">\r\n
<ul>\r\n
<span id="languageForStatic" style="display: none">nl</span>\r\n
<!-- IT-4522 The design team uses languageForStatic to display text dynamically-->\r\n
\r\n
\r\n
<li class="active"><a href="?lang=nl" tabindex="-1">NL</a></li>\r\n
<li><a href="?lang=fr" tabindex="-1">FR</a></li>\r\n
\r\n
\r\n
\r\n
</ul>\r\n
</div>\r\n
</div>\r\n
\r\n
<div class="branding clearfix">\r\n
<div id="logo"><img src="https://static.site.be/oauth2/images/logosite.png"\r\n
data-at2x="https://static.site.be/oauth2/images/logosite.png@2x.png"\r\n
alt="site"></div>\r\n
<h1><label>Fout bij aanmelden</label></h1>\r\n
<span id="languageForStatic" style="display: none">nl</span>\r\n
<!-- IT-5252 The design team uses languageForStatic to display text dynamically-->\r\n
</div>\r\n
<div class="contentContainer">\r\n
<p>Er ging iets mis. Gelieve de applicatie af te sluiten en daarna opnieuw op te starten.</p>\r\n
</div>\r\n
</div>\r\n
\r\n
\r\n
</div>\r\n
<div class="copyright">© site\r\n
<script>document.write(new Date().getFullYear());</script>\r\n
- <a href="http://klantenservice.site.be/content/juridische-informatie" target="_blank"\r\n
tabindex="-1">Juridische informatie</a>\r\n
- <a href="https://www2.site.be/nl/privacy/"\r\n
href="https://www2.site.be/nl/privacy/" target="_blank"\r\n
tabindex="-1">Privacy</a><br>\r\n
<a href="http://klantenservice.site.be/content/waar-vind-ik-de-algemene-voorwaarden-van-site" target="_blank"\r\n
tabindex="-1">Tariefinfo en algemene voorwaarden</a>\r\n
</div>\r\n
</div>\r\n
<div class="bgContainer"></div>\r\n
</div>\r\n
\r\n
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>\r\n
<script src="/openid/js/vendor/modernizr-2.6.2-respond-1.1.0.min.js"></script>\r\n
<script src="/openid/js/vendor/retina-1.1.0.min.js"></script>\r\n
\r\n
<!--[if lt IE 9]>!\r\n
<script type="text/javascript" src="/openid/js/vendor/jquery.backgroundSize.js"></script>!\r\n
<![endif]-->\r\n
\r\n
<script src="https://static.uat.site.be/oauth2/js/items.js"></script>\r\n
<script src="https://static.uat.site.be/oauth2/js/main.js"></script>\r\n
\r\n
</body>\r\n
</html>\r\n
"""
“”“
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
站点:Meld je aan\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
函数hideHtmlElement(id){\r\n
document.getElementById(id).style.display=“无”;\r\n
}\r\n
\r\n
函数showHtmleElement(id){\r\n
document.getElementById(id).style.display=“块”\r\n
}\r\n
\r\n
函数显示面板(id){\r\n
hideHtmlElement(“放弃登录”);\r\n
hideHtmlElement(“showLogin”);\r\n
hideHtmlElement(“放弃密码”);\r\n
ShowHtmleElement(id);\r\n
}\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
正确\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
nl\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
Fout bij aanmelden\r\n
nl\r\n
\r\n
\r\n
\r\n
呃,这是错误的。从开始到结束,应用程序都在运行。\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
&抄袭;站点\r\n
document.write(新日期().getFullYear())\r\n
-\r\n
-
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
"""
我现在陷入困境,我不知道我做错了什么,我不知道下一步该怎么办
问题 如何转换卷曲以获得相同的结果 这是我需要在PHP curl设置中启用的吗 我需要更新Apache设置吗 我的PHP卷发怎么了
如何进一步进行调试?最有可能的问题是,您的第一个请求失败,因为您没有正确设置SSL验证。您必须为两个请求设置相同的CURL选项。区别只是URL和POST数据 因此,代码应该如下所示:
$cookie_file = public_path(). '/session_cookies.txt';
if (!file_exists($cookie_file)) return;
$pem_file_path = '/Applications/MAMP/conf/apache/openid.benu.com.cert.pem';
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_CAINFO=> $pem_file_path,
CURLOPT_POST => true,
CURLOPT_COOKIEJAR => $cookie_file,
CURLOPT_COOKIEFILE => $cookie_file,
);
$ch = curl_init('https://login.uat.site.be/openid/oauth/authorize');
curl_setopt_array($ch, $options);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array(
'client_id' => 'benu',
'state' => $state,
'nonce' => $nonce,
'claims' => '%7B%22id_token%22%3A%7B%22http%3A%2F%2Fsite.be%2Fclaims%2Froles%22%3Anull%7D%7D',
'response_type' => 'code'
)));
$result = curl_exec($ch);
$err = curl_errno($ch);
curl_close($ch);
if ($err) {
echo 'Error:' . curl_error($ch); return;
}
$ch = curl_init('https://login.uat.site.be/openid/login.do');
curl_setopt_array($ch, $options);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array(
'j_username' => 'manager-sitelogin@gmail.com',
'j_password' => 'site1',
)));
$result = curl_exec($ch);
$err = curl_errno($ch);
curl_close($ch);
if ($err) {
echo 'Error:' . curl_error($ch);
}
垃圾是登录页面,我相信它是说你没有登录(“呃,让我们管理信息系统…”)。这就意味着您的第一个OAuth cURL失败,或者您的第二阶段用户名/密码失败。我建议将命令行第一个cURL的输出与第一阶段PHP版本的输出进行比较。一旦两者相同,就进入第二阶段。另外,您不需要
urlencode
您的用户名。哦,真的吗。我将删除urlencode并重试。是的,根据文档:“默认情况下,PHP_QUERY_RFC1738正在编码。。。根据RFC 1738和应用程序/x-www-form-urlencoded media type执行,这意味着空格编码为加号(+)。”