?
Solved

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

Posted on 2008-10-20
4
Medium Priority
?
758 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
[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 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 500 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

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

Question has a verified solution.

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

For some reason Google Apps has decided to reserve 'www' for your new domain which results in an error when trying to map the web address 'www' to a certain site in your Google Sites. The error is 'this address is already being used' and after some …
The task of choosing a web design company to build a website for your business should never be taken in a light manner. Provided the fact that your website will act as a representative to your business and will be responsible for imposing an online …
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month14 days, 21 hours left to enroll

771 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