Solved

How do I send HTTPS POST to web service using XML and PHP?

Posted on 2008-10-20
4
751 Views
Last Modified: 2013-11-10
We have to send a request to a web service using HTTPS POST.  The code below is the XML that we will send. It sends a UPC number that comes from our MySQL database on an Apache server. The web service then responds with the product details associated with the UPC number. We send the POST to:

https://Secure.Website.Com/Webservices/upc.Exe/onlinestore

We are planning to use PHP to create and process the POST. We're trying to keep it simple.

Is this correct? We create a simple html form that pulls the UPC from our database (no problem there).  Our html form uses a php script that we create for the action in the form. This PHP script assembles the XML request and passes it via HTTPS POST to the web service.

Assuming this is essentially correct, we are looking for any samples of the PHP script necessary to assemble the data and process the POST.

Thanks a bunch.
<TRANSACTION>
 

   <RNCERT>BDF95</RNCERT>
 

   <TRANSACTIONTYPE>GETUPCINVENTORY</TRANSACTIONTYPE>
 

   <UPC>883929015368</UPC>
 

   <SHOWITEMDETAILS>TRUE</SHOWITEMDETAILS>
 

 </TRANSACTION>

Open in new window

0
Comment
Question by:LyleHolmes
  • 2
  • 2
4 Comments
 
LVL 8

Expert Comment

by:MatthiasVance
ID: 22765229
Assuming you have curl installed, you can do the following.

Kind regards,

Matthias Vance
<?php
 

function postHttps($url, $request) {

	$ch = curl_init();

	curl_setopt($ch, CURLOPT_URL, $url);

	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

	curl_setopt($ch, CURLOPT_POST, 1) ;

	curl_setopt($ch, CURLOPT_POSTFIELDS, $request);

	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

	$result = curl_exec($ch);

	curl_close($ch);

	return $result;

}
 

?>

Open in new window

0
 
LVL 8

Accepted Solution

by:
MatthiasVance earned 125 total points
ID: 22765238
Sorry, I forgot to add an example.
<?php

echo postHttps("https://webservice/", utf8_encode(file_get_contents("data.xml")));

?>

Open in new window

0
 

Author Comment

by:LyleHolmes
ID: 22767208
Thanks Matthias,

I assume the php/echo is on the page with "https://webservice" being replaced by the actual URL that we are going to post to.

Do we define the fields being delivered within the CURL using variables?
0
 

Author Comment

by:LyleHolmes
ID: 22772390
Hey Matthias,
Your code worked very well.
Thanks for the input.
Lyle
0

Featured Post

Are your corporate email signatures appalling?

Is it scary how unprofessional your email signatures look? Do users create their own terrible designs and give themselves stupid job titles? You can make this a lot easier for yourself by choosing an email signature management solution from Exclaimer today.

Question has a verified solution.

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

To properly understand GitHub, let’s divide it into two words ‘Git’ and ‘Hub’. Git is basically a ‘Distribution Version Control’ (DVC) and ‘Source Code Management’ (SCM) system widely used by software programmers while Hub means the efficient centre…
In order to have all security and back ups taken care of, WordPress users can sign up for services with WP Engine.
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

867 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

22 Experts available now in Live!

Get 1:1 Help Now