使用php curl发布saml文件并将C#代码转换为php

I am trying to httpost saml file in php using curl for sso purposes but the xml contents need to be encoded into byte utf8 and then base64(that's the requirements of the company i am posting to) so they gave me this piece c# and they told me to convert it to php this is what i get to so far with my php curl saml post:


<?php
$url = "https://my.sandbox.company.com/sso/authenticate.ashx";
$filename = "saml.xml";
$handle = fopen($filename, "r");
$XPost = fread($handle, filesize($filename));
echo urlencode($XPost);
fclose($handle);

$decdata = urlencode($XPost);
$raw = base64_encode($decdata);


$ch = curl_init();

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);


curl_setopt($ch, CURLOPT_VERBOSE, 1); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
//curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 40); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $raw);
curl_setopt($ch, CURLOPT_POST, 1);

$result = curl_exec($ch); // run the whole process
if (empty($result)) {
die(curl_error($ch));
curl_close($ch); // close cURL handler
} else {
$info = curl_getinfo($ch);
curl_close($ch); // close cURL handler
if (empty($info['http_code'])) {
die("No HTTP code was returned");
} 
else {
echo "The server responded: 
";
echo $info['http_code'] . " " . $http_codes[$info['http_code']];
}
}

echo "RESULT: $result"; //contains response from server

?>

The C# code given

string responseStr = doc.OuterXml;
byte[] base64EncodedBytes = Encoding.UTF8.GetBytes(responseStr);
string returnValue = System.Convert.ToBase64String(base64EncodedBytes);

Please let me know if my code is wrong. Thank you

dtjkl42086
dtjkl42086 对不起,它没有正确验证
大约 7 年之前 回复
dqv84329
dqv84329 url的帖子正在运行,但是它正确地进行了身份验证。它会将我重定向到他们的注册页面
大约 7 年之前 回复
ds122455
ds122455 它是否按预期运行?目前有什么问题吗?
大约 7 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐