Solved

Sending XML data via HTTPS in PHP

Posted on 2003-11-06
4
340 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

756 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