phpnewb999 Posted June 26, 2006 Share Posted June 26, 2006 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/perluse LWP;use LWP::UserAgent;use Getopt::Std;use strict;use constant BASE_URL => 'https://post.mysite.org/bulk;# process optionsmy $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 filemy $content = undef;open(CFH, "<$filename") || die "can't open $filename for read: $!";{ local $/ = undef; $content = <CFH>; }close(CFH);# prepare requestmy $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 requestmy $res = $ua->request($req);# print resultif($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 https://forums.phpfreaks.com/topic/12895-https-connection/ Share on other sites More sharing options...
trq Posted June 26, 2006 Share Posted June 26, 2006 Yes. Using the [a href=\"http://php.net/curl\" target=\"_blank\"]curl[/a] extension. Link to comment https://forums.phpfreaks.com/topic/12895-https-connection/#findComment-49511 Share on other sites More sharing options...
phpnewb999 Posted June 27, 2006 Author Share Posted June 27, 2006 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 https://forums.phpfreaks.com/topic/12895-https-connection/#findComment-50080 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.