Jump to content

HTTPS Connection?


phpnewb999

Recommended Posts

Is there a way to establish a https connection with php that is similar to the code below which is written in perl?

#!/usr/bin/perl
use LWP;
use LWP::UserAgent;
use Getopt::Std;
use strict;

use constant BASE_URL => 'https://post.mysite.org/bulk;

# process options
my $opts = {};
getopts('o:f:p', $opts);
my $post = $opts->{'p'};
my $filename = $opts->{'f'};
my $outfile = $opts->{'o'};
unless($filename) {
print "usage: $0 [-p] [-o outfile] -f filename\n".
" options:\n".
" -f - the name of the RSS file to submit (required)\n".
" -p - actually post (otherwise just validate)\n".
" -o - output filename (otherwise results sent to STDOUT)\n\n";
exit(0);
}

# open file
my $content = undef;
open(CFH, "<$filename") || die "can't open $filename for read: $!";
{ local $/ = undef; $content = <CFH>; }
close(CFH);

# prepare request
my $ua = LWP::UserAgent->new();
$ua->agent('SampleBulkPostClient/0.1');
my $post_url = BASE_URL .'/'. ($post? 'post': 'validate');
my $req = HTTP::Request->new( POST => $post_url );
$req->content_type('application/x-www-form-urlencoded');
$req->content($content);

# issue request
my $res = $ua->request($req);

# print result
if($res->is_success()) {
if($outfile) {
open(OFH,">$outfile") || die "can't open $outfile for write: $!";
print OFH $res->content();
close OFH;
}
else {
print $res->content()."\n";
}
}
else {
print "request failed:\n".
$res->status_line()."\n".$res->content()."\n";
}
Link to comment
Share on other sites

I finally got the Curl extension installed and wrote a little code (which of course is not working :( )

[code]
$fp = fopen("sample.xml", "r")
$url = "https://mysite.com"
$ch = curl_init()
curl_setopt ($ch, CURLOPT_HTTPHEADER, Array("Content-Type: application/x-www-form-urlencoded"))
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1)  
curl_setopt($ch, CURLOPT_UPLOAD, 1)  
curl_setopt($ch, CURLOPT_INFILE, $fp)  

$result = curl_exec($ch)
curl_close ($ch)
print $result
[/code]

What i need to do is establish a https connection, send a http request with content of "application/x-www-form-urlencoded" containing the sample.xml content.

Any help as to what i'm doing wrong pls.

Thanks
Link to comment
Share on other sites

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.