Jump to content

Recommended Posts

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

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!

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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.