Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Sending XML data via HTTPS in PHP

Posted on 2003-11-06
4
Medium Priority
?
345 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 1400 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

609 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