Solved

Sending XML data via HTTPS in PHP

Posted on 2003-11-06
4
341 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Put POST values into cookies. 14 50
assigning javascript variable to php variable 8 64
Code not executing correctly. 3 41
emailing registered email addresses in phpmyadmin 5 48
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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 count occurrences of each item in an array.

738 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