Solved

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

Posted on 2008-10-20
4
755 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 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Denial of Service Attack 4 42
WCF doubts 3 78
Ezidebit payment gateway 5 107
Automation Testing for REST API - Where to start? 3 125
When coding a Webservice to provide data, the normal way is to create a method that returns a Dataset object.   But a Dataset cannot be used easily from another platform, such as PHP,  FLAS (FLEX) , etc. Solution : Return a XML Document instea…
New Relic recently released its Synthetics product that allows for the creation of performance monitors that periodically test a site's performance. If you wish to test an interactive workflow New Relic employs Selenium WebDriverJS to run those test…
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 a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

696 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