Strikeplate Posted July 25, 2009 Share Posted July 25, 2009 Greetings... I'm in a bind so I'm hoping the community can lend me a hand. Short overview. I've developed an application for a client, but to get to it I have to handshake through their SSO protocol, which sends xml data back and forth to authenticate users. They provided me with access to their test server and I put snippets and research together to come up with a curl script that works. Here that is (in part): $request_xml = "$data"; // this is the parsed xml that I am sending to their server requesting information $ch = curl_init("http://www.myclientsserver.com/folder/authority.sso"); // this is where I'm sending the request to curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $request_xml); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $response_xml = curl_exec($ch); $xmlDoc = new DOMDocument(); $xmlDoc->loadXML($response_xml); $x = $xmlDoc->getElementsByTagName('scope'); foreach ($x AS $item) { $scopeCode = $item->getAttribute("value"); // this gives me what I'm looking for, the value of the "scope" tag } As I said, this works flawlessly on their test server. So what's the problem? When I went to deploy it they sprung on me that their production server is https not http. So I tried simply changing this line: $ch = curl_init("https://www.myclientsserver.com/folder/authority.sso"); // simply added the "s" But all I get back now is a blank page. In doing additional research it seems that using curl with https is a bit tricky...but possible from what I can tell. Problem is I haven't been able to do it myself! My client thinks that the problem lies with my server not accepting their SSL cert, but given what I've read on the subject, I tend to believe it is curl. I have to figure this out by Monday, so I am hoping that someone can shed some light on this for me. It would be greatly appreciated indeed! Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/167405-solved-curl-and-https/ Share on other sites More sharing options...
Daniel0 Posted July 25, 2009 Share Posted July 25, 2009 You might try to set CURLOPT_SSL_VERIFYPEER to false. Link to comment https://forums.phpfreaks.com/topic/167405-solved-curl-and-https/#findComment-882740 Share on other sites More sharing options...
Strikeplate Posted July 25, 2009 Author Share Posted July 25, 2009 You might try to set CURLOPT_SSL_VERIFYPEER to false. I probably should have mentioned that I did try that...no go. I'm working with someone who told me that only certain versions of the curl package support SSL. So at the moment I'm installing a version that supposedly is one of the ones that does. If that is successful I will post that info here as it seems like a number of people have already stopped by to read this post. In the meantime, of course if anyone else has a code-based suggestion I'd love to hear it! Link to comment https://forums.phpfreaks.com/topic/167405-solved-curl-and-https/#findComment-882788 Share on other sites More sharing options...
Strikeplate Posted July 27, 2009 Author Share Posted July 27, 2009 It took awhile but I came up with a solution! For those interested here is how I got curl working with SSL/HTTPS: $request_xml = "$xmlData"; //this is my parsed XML $url = "https://www.example.com"; //this is where I'm posting XML to $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSLVERSION, 3); //this tells curl its SSL! curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // this bypasses cert varification - you may not want this but mine was a trusted source curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1); // this verifies the domain curl_setopt($ch, CURLOPT_VERBOSE, TRUE); // this provides error info curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $request_xml); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_HEADER, 0); // this removes http headers - important if you are dealing with XML curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // this returns the contents of the call $response_xml = curl_exec($ch); // this puts contents of call into a variable You may have to play a bit depending on your needs, but hopefully it will help someone who is pulling their hair out like I was! Link to comment https://forums.phpfreaks.com/topic/167405-solved-curl-and-https/#findComment-883575 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.