View Full Version : HTTPS connections

03-20-2009, 04:41 PM
Hi Guys
This is probably a simple error, its just i've never dealt with these before and google didn't seem to give me any luck.

I'm installing a script and step 2 says:

After a successful authentication, it redirects the user back to the token_url at your website as specified in step 1. Write some code to handle requests to your token_url, and extract the token parameter.

Make the auth_info API call

HTTP POST to https://url.com (url edited) with the following required parameters:
apiKey Key Removed
token Use the token sent to your token_url

How can I post the data to the url and get the response that's produced? I can't really see where to go with this. A fopen() produced a "400 BAD REQUEST" response, and other than that I don't really know where to go, so any help would be highly appreciated.


03-20-2009, 08:05 PM
You may want to make sure allow_url_fopen is enabled in your PHP configuration.


03-21-2009, 01:47 AM
Thanks for that response. It seems to open external pages at the moment, so I've sieved through existing code and got a little bit further, but still not all the way. Just as a sample, I've included my request, the php code and the servers response. Any help would be brilliant. thanks

$token = $_GET['token'];

$fp = fsockopen("rpxnow.com", 443, $errno, $errstr, 5);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "POST ssl://rpxnow.com/api/v2/auth_info?apiKey=REMOVED&token=".$token."&format=xml HTTP/1.0\r\n";
$out .= "Host: rpxnow.com\r\n";
$out .= "Content-Type: application/x-www-form-urlencoded\r\n";
$out .= "Content-Length: 0\r\n";
$out .= "Connection: Close\r\n\r\n";
echo no_html($out).'<br/><br/>';
fwrite($fp, $out);
while (!feof($fp)) {
$data = fgets($fp, 128);
$data = no_html($data);
echo $data;

function no_html($s) {
$s = str_replace("<", "&lt;", $s);
$s = str_replace(">", "&gt;", $s);
$s = str_replace("\r\n", "<br/>", $s);

Have also tried http:// and https:// as well as ssl:// after POST:

POST https://rpxnow.com/api/v2/auth_info?apiKey=REMOVED&token=REMOVED&format=xml HTTP/1.0
Host: rpxnow.com
Content-Type: text/html
Content-Length: 0
Connection: Close

HTTP/1.1 400 Bad Request
Server: nginx/0.6.32
Date: Fri, 20 Mar 2009 23:19:58 GMT
Content-Type: text/html
Content-Length: 271
Connection: close

<head><title>400 The plain HTTP request was sent to HTTPS port</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<center>The plain HTTP request was sent to HTTPS port</center>

Just to let you know, when trying to send to a port 80, I get this:

HTTP/1.1 301 Moved Permanently
Server: nginx/0.6.32
Date: Fri, 20 Mar 2009 23:48:01 GMT
Content-Type: text/html
Content-Length: 185
Connection: close
Location: https://rpxnow.com/api/v2/auth_info?apiKey=REMOVED&token=REMOVED&format=xml

<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>

Thanks once again!
And, as a side note, I'm not a good coder