top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How can I set arbitrary headers on a request?

+5 votes
560 views
How can I set arbitrary headers on a request?
posted Dec 30, 2015 by Vrije Mani Upadhyay

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
I am not clear about your question please describe.

1 Answer

+1 vote
 
Best answer

If you are talking about making a request and specifying your headers, one way to do it is using CURL:

$data = "<soap:Envelope>[...]</soap:Envelope>"; 
$tuCurl = curl_init();
curl_setopt($tuCurl, CURLOPT_HEADER, 0);
curl_setopt($tuCurl, CURLOPT_URL, "http://example.com/path/for/soap/url/");
curl_setopt($tuCurl, CURLOPT_POST, 1); // if post request
curl_setopt($tuCurl, CURLOPT_POSTFIELDS, $data);
curl_setopt($tuCurl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($tuCurl, CURLOPT_HTTPHEADER, array("Content-Type: text/xml","SOAPAction: \"/soap/action/query\"", "Content-length: ".strlen($data)));
$tuData = curl_exec($tuCurl); 
if(!curl_errno($tuCurl)){ 
  $info = curl_getinfo($tuCurl); 
  echo 'Took ' . $info['total_time'] . ' seconds to send a request to ' . $info['url']; 
} else { 
  echo 'Curl error: ' . curl_error($tuCurl); 
} 
curl_close($tuCurl); 
echo $tuData; 
answer Feb 23, 2016 by Rahul Singh
Similar Questions
+1 vote

We have a service where we have a front end using Wordpress/Magento/custom PHP code and a distributed backend using various other servers and services from note.js, magento, mysql, c#, java, ms sqlserver, Apache, etc.

The idea is we want to have multiple UIs spread across different geographies (different USA states, different countries, etc.) either user selectable or load-balancer assigned

How can we have it set up such that someone's login/authentication is valid across the different UIs (and can switch amongst them) without re-logging in when they switch (after having logged in already to any of the nodes). I don't want to have to constantly authenticate against some shared backend for every request either, so I imagine some kind of token must be used? Like how does OpenID work? Or these "Login with Facebook" or "Google ID"? Amazon AWS/EC2 are good examples for their UI console to manage computes as it has different regions at the top you switch to simply by the dropdown and really nothing else changes except some AJAX reload of your statistics, even the URL is mostly the same except another parameter.

We're not necessarily married to Wordpress and in fact we're trying to phase it out eventually and only use Magento.

Custom code is also an option - at least if there is a good example base or API we can maybe hack it in.

We're open to many technologies, but obviously would prefer to use one we already have (PHP ideally)

Any pointer will be helpful?

...