Monday, February 10, 2014

How to change Content-Type in SoapClient php / http headers

Hi to everyone,

This is simple manual how to change content type in http header for php class SoapClient

1. You should determine which soap version you are using:

There is way to set it soap 1.1 or soap 1.2
depending on that your version content type should be for 1.1:
Content-Type: text/xml; charset=utf-8
---
$client = new SoapClient('my.wsdl', array('soap_version' => SOAP_1_1,
"trace" => 1, 
"exception" => 0);
---
ver 1.1 is set by default so you don't even need to mention it in options array.

and for 1.2:
Content-Type: application/soap+xml; charset=utf-8
---
$client = new SoapClient('my.wsdl', array('soap_version' => SOAP_1_2,
"trace" => 1, 
"exception" => 0);
---

but SoapClient adds optional param action to Content-Type so it looks like:

Content-Type: application/soap+xml; charset=utf-8; action=""

In order to change Content-Type (applies to both 1.1 and 1.2) you should override SoapClient method __doRequest() to use cURL for forming and sending request

class myNewSoapClient extends SoapClient {

     public function __doRequest($request, $location, $action, $version, $one_way = FALSE)

     {

$curl = curl_init($location);   

curl_setopt($curl, CURLOPT_VERBOSE, FALSE); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); 
curl_setopt($curl, CURLOPT_POST, TRUE); 
curl_setopt($curl, CURLOPT_POSTFIELDS, $request); 
curl_setopt($curl, CURLOPT_HEADER, FALSE); 
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/soap+xml;charset=UTF-8")); 
$response = curl_exec($curl);   

if (curl_errno($curl)) { 

throw new Exception(curl_error($curl)); 
}   

curl_close($curl); 


if (!$one_way) { 

return ($response); 
}
     } 
} 

So now you can change your Content-Type to anything you want or need.
Later you can use your new class this way:

$client = new myNewSoapClient('my.wsdl', array('soap_version' => SOAP_1_2,
"trace" => 1, 
"exception" => 0);
$client->__setLocation(EP_MTEL_ENDPOINT_SOAP_URL);


// Call the SOAP method
try{
$result = $client->__soapCall($service_name, $params, array('soapaction' => null));
}

catch(Exception $e){
       var_dump($e->getMessage());
}

I hope that this will help someone.

Friday, October 19, 2012

After 10.000 posts long SEO experiment

Since I have founded this blog my decision was to start some experiments with SEO, that was long time ago. My expectations were big, as first article from this blog have appeared in the Google after 15 minutes since I have published it.
In that time I have discovered one Google's service called Google Trends, but I was frustrated because I was able to see only top ten searches for last hour, and I was trying to find way how to save searches every hour and than later make some analysis what is the most popular thing to write about.
First I was needed to make simple machine that will grab the page with trends and save them to database. As they added RSS Feed to their service the thing become much easier. I was parsing the feed and saving it's contents to the database.
My main question about SEO was how to be there right on time and catch audience before others, so I have decided to extend my little app and make another part of it.
Second part of my application was small engine that was using the first item from trends (the most popular one), and searched Google News for it. After that it was grabbing the first five results from Google News with their descriptions and saving them to the database, so later I was able to make automatic publishing of investigations results via Blogger to this blog. (The main goal was to make hot news that are useful during the time - the news website that is doing it's job alone)
First thing that I need to mention is that this blog was not so much useful as tool when you are reading it directly on the web, but you were able to subscribe to it's RSS, and have one post in an hour: top 10 searches on Google in USA and first five news results about the most popular search query at the moment. The important part was that you had complete history hour by hour. This thing was developed as extension to Google trends service for lazy people :).
The idea was that I will connect Google's services in order to make me some money for doing nothing, but it was just an experiment.

The idea included following services:
1. Google Trends (to see what is hot on the Internet)
2. Blogger (as great and free publishing service)
3. Google AdSense (to place ads in Feeds and on blog so that it can generate some revenue)
4. Google as Search engine (the best place for people to find my new service)

And you are probably expecting to hear how much money I have earned after 10.000 hours :), the sum is 0.14 eur 

I have already can hear how SEO experts saying that I have missed several points in this experiment, and that my experiment was barely legal, but you don't know until you don't try.

Now I'm cancelled whole operation as Google had changed the Trends tool in the way I like it, and ads for feeds also will be stooped as service on December 3rd.

Since now I will be using this blog to share my ideas and experiences about many things on the Internet including the SEO.

Have nice weekend and do not waste you time until you don't know what are you trying to achieve. :)