Solved

Sending XML data via HTTPS in PHP

Posted on 2003-11-06
4
339 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 Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

828 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