Solved

Sending XML data via HTTPS in PHP

Posted on 2003-11-06
4
336 Views
Last Modified: 2011-09-20
What is the easiest way to send a chunk of XML data to a specific HTTPS url and receive the response? (I am not concerned with parsing the returned XML at this point, I just want to display the response).  I am running PHP 4.2.3- do I need to upgrade to 4.3 to do this via HTTPS?  (I do have CURL installed though)..  please let me know the fastest way to get this done without having to recompile PHP if possible.  This should be a pretty simple answer but it is urgent so good points for this one... (please provide code snippet if possible)

thanks!
0
Comment
Question by:invizabul
  • 2
  • 2
4 Comments
 
LVL 4

Accepted Solution

by:
meet_zorrer earned 350 total points
ID: 9697314
Here is the code and solution of all your problems

$ch = curl_init(); // initalize cURL

//if FALSE the ssl error compare of certificate from our server
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
      
curl_setopt($ch, CURLOPT_URL, $url); // connect to any HTTPS URL

// take the $XML and and turn it into name=value pair
if (count($request) > 0)
{
      $str= .$name."=".$XML; //your XML will be in $XML
}


if(!curl_setopt($ch, CURLOPT_POST, 1)) // we're doing a post
{
      print "Err# 1....";
}

if(!curl_setopt($ch, CURLOPT_POSTFIELDS, $str)) // name=value pairs from above
{
            print "Err# 2....";
}

if(!curl_setopt($ch, CURLOPT_USERAGENT, "My Agent (Windows)"))
{
      print "Err# 3....";
}


if(!$temp=curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1)) // return results
{
      print "Err# 4....";
      print "<br>";
}


$results = curl_exec ($ch); // connect and grab the results
print $results;
print curl_error($ch);
curl_close ($ch);

Regards,
Meet
0
 

Author Comment

by:invizabul
ID: 9697394
is there a way to send the XML as a file or some other way than posting it as a name value pair?  it doesn't appear that the target URL can accept the XML data as a name/value pair....  

0
 
LVL 4

Expert Comment

by:meet_zorrer
ID: 9697517
It depends on your target location,

If that url server is not accepting POST and GET data then how did you come to know that
you need to send the question that you want to send the Chunk of XML data to a URL?
Give me some example how you want to send the XML to a URL
like say
http://www.server.com/page.php?XML=<AXML>DATA</AXML>

if your target location required XML in a file then just send the XML file just like a normal file upload and set the
form's encoding property to  multipart/form-data

Regards,
Meet
0
 

Author Comment

by:invizabul
ID: 9697809
my fault, it would accept a name value pair, i was just using the wrong name-   the above code worked fine with minor modifications-  thanks!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now