Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php curl发布saml文件并将C#代码转换为php_C#_Php_Curl_Single Sign On_Saml - Fatal编程技术网

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

使用php curl发布saml文件并将C#代码转换为php,c#,php,curl,single-sign-on,saml,C#,Php,Curl,Single Sign On,Saml,我试图使用curl在php中为sso目的对saml文件进行httpost,但xml内容需要先编码为字节utf8,然后再编码为base64(这是我发布到的公司的要求),所以他们给了我这篇文章c,并告诉我将其转换为php 这是我到目前为止在php curl saml文章中得到的内容: 如果我的代码错了,请告诉我。 谢谢它是否按预期运行?当前是否存在任何问题?到url的帖子正在工作,但正在正确验证。它会将我重定向到他们的注册页面抱歉,它没有正确验证 <?php $url = "https:/

我试图使用curl在php中为sso目的对saml文件进行httpost,但xml内容需要先编码为字节utf8,然后再编码为base64(这是我发布到的公司的要求),所以他们给了我这篇文章c,并告诉我将其转换为php 这是我到目前为止在php curl saml文章中得到的内容:



如果我的代码错了,请告诉我。
谢谢

它是否按预期运行?当前是否存在任何问题?到url的帖子正在工作,但正在正确验证。它会将我重定向到他们的注册页面抱歉,它没有正确验证
<?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: \n";
echo $info['http_code'] . " " . $http_codes[$info['http_code']];
}
}

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

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