Issue in curl connecting with Ip address in zend - php

Dear Supporter,
$data=array(
"themeName"=>"gghg"
);
$adapter = new Zend_Http_Client_Adapter_Curl();
$adapter->setConfig($curlOption);
//instantiate the http client and add set the adapter
$client = new Zend_Http_Client("http://50.55.146.221/curl_page.php");
$client->setAdapter($adapter);
//add the post parameters from our config file (the authentication part)
$client->setParameterPost($data);
//perform the post, and get the response
$response = $client->request(Zend_Http_Client::POST);
Error :
Fatal error: Uncaught exception 'Zend_Uri_Exception' with message 'Invalid URI supplied' in /var/www/html/ursify/Source/ursify.com/library/Zend/Uri/Http.php:
I am trying to create client object "$client = new Zend_Http_Client("http://50.55.146.221/curl_page.php");"
Where i am doing wrong ? Help me

Seems everything fine. I've tested your code and there are no errors except timeout in cUrl call. I've tested with ZF 1.12.7

Related

400 (Bad Request) when calling listGroups() method with Google API PHP client

I want to retrieve all groups in my domain. I'm using google api php client and have the following error when i try it :
$client = new Google_Client();
...
$directory = new Google_Service_Directory($client);
$directory->groups->listGroups();
Error calling GET https://www.googleapis.com/admin/directory/v1/groups: (400) Bad Request
Do you know how can i fix it ?
The problem has been fixed. I had to specify a domain in the listGroups() function :
$directory->groups->listGroups(array('domain' => 'mydomain.com'));
For me, the issue fixed by specifying userKey instead of domain

Receive error when running basic nuSOAP tutorial

I am trying to create a website that retrieves data from a Web Service using the site API.
The 'nuSOAP' PHP library seems to be a perfect way to go about this and so I have been trying to run through a basic tutorial by Scott Nichol called 'Introduction to NuSOAP'.
Here is the code for server.php:
<?php
// Pull in the NuSOAP code
require_once('nusoap.php');
// Create the server instance
$server = new soap_server;
// Register the method to expose
$server->register('hello');
// Define the method as a PHP function
function hello($name) {
return 'Hello, ' . $name;
}
// Use the request to (try to) invoke the service
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>
...and here is the code for the client.php:
<?php
// Pull in the NuSOAP code
require_once('nusoap.php');
// Create the client instance
$client = new soapclient('http://localhost/beehive/server.php');
// Call the SOAP method
$result = $client->call('hello', array('name' => 'John'));
// Display the result
print_r($result);
?>
I have 'XAMMP' installed and so when I call up client.php via the browser it should bring up a basic page that says 'Hello, John' but instead I get the following error message:
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from '.../server.php' : Start tag expected, '<' not found in C:\xampp\htdocs\beehive\client.php:7 Stack trace: #0 C:\xampp\htdocs\beehive\client.php(7): SoapClient->SoapClient('http://...') #1 >{main} thrown in C:\xampp\htdocs\beehive\client.php on line 7
I figured I should be loading the client page rather than the server, but if I load server.php then I get the error message 'This service does not provide a Web description'.
I have followed the tutorial exactly and can't figure out why it's throwing this error; can anyone please help?
Thank you!
The error you receive makes perfect sense with your error description. The server isn't responding with the right format and therefor your client breaks.
The same error is discussed here:
nusoap simple server
You need to point the client constructor to your wsdl file...
$client = new soapclient('http://localhost/beehive/server.php');

HTTP 417 error (Expectation Failed) while posting file to web server via Guzzle

I am using Guzzle in Laravel 4 to send file to the remote server which the server will then process. But while posting the file to the server I'm getting the following exception occurs:
Guzzle \ Http \ Exception \ ClientErrorResponseException
Client error response [status code] 417 [reason phrase] Expectation Failed [url] http://example.com/.....
Following is the code that I am using:
use Guzzle\Service\Client as GuzzleClient;
use Guzzle\Plugin\Cookie\Cookie;
use Guzzle\Plugin\Cookie\CookiePlugin;
use Guzzle\Plugin\Cookie\CookieJar\ArrayCookieJar;
$remote_url = 'http://example.com/';
$client = new GuzzleClient($remote_url);
$client->setSslVerification(FALSE);
$cookieJar = new ArrayCookieJar();
// Create a new cookie plugin
$cookiePlugin = new CookiePlugin($cookieJar);
// Add the cookie plugin to the client
$client->addSubscriber($cookiePlugin);
$post_data = array(
'username' => $input['username'],
'password' => $input['password'],
);
$response = $client->post('login', array(), $post_data)->send();
$response_json = $response->json();
if (isset($response_json['error'])) {
throw new Exception($response_json['error']);
}
$current_time = date("Y-m-d-H-i-s");
$file = 'C:\test\test_file.zip';
$request = $client
->post('receiveFile')
->addPostFields(array('current_time'=>$current_time))
->addPostFile('file', $file)
->send();
The authentication of user seems to work fine and the problem starts only when trying to send the file.
The application throws the error only when I'm trying to send the file to the web server. When I try to send the same file to the same application on my local server, I'm getting the results as I expected without any errors.
I looked for similar problems other people might have faced and found one here on SO Posting a file to a web service with Guzzle , but the solution that worked for the OP of that question didn't work for me. What can I do to solve this problem?
It turned out that when sending the request, a Expect header is added to the request. So what I did was remove the Expect header before sending the request, and everything is working as it should. Following is the code that I changed:
$request = $client
->post('receiveFile')
->addPostFields(array('current_time'=>$current_time))
->addPostFile('file', $file)
->removeHeader('Expect')
->send();
I used the removeHeader method to remove the Expect header. Looks like the removeHeader method must be called just before using the send method, because I had used it before the post method and it hadn't worked before.

Login Api AdWords in PHP (Codeigniter) without auth.ini

I'm developing an app in php with codeigniter that needs to connect to Adwords, and I have a lot of questions...
First of all, I have a test account and I don't know if i'm connecting properly, because I don't know what I have to put as developerToken, clientId and defaultServer. Which is the correct one?
$username = "my_email#gmail.com";
$password = "my_password";
//Developer Token options
$developerToken_1 = "E2SGs1l7gEWWdCfeYSO4oA"; //It's not my real token..
$developerToken_2 = "my_email#gmail.com++USD";
$user = new AdWordsUser(null, $username, $password, $developerToken);
//Default Servers
//Option 1
$user->SetDefaultServer("https://adwords.google.com/");
//Option 2
$user->SetDefaultServer("https://adwords-sandbox.google.com");
//Option 3
$user->SetDefaultServer("https://sandbox.google.com");
//Client ID
//Option 1
$user->SetClientId('client_id_1+my_email#gmail.com');
//Option 2
$user->SetClientId('1234567890');
I think that I have to use the adwords version v201306
$campaignService = $user->GetService('CampaignService', 'v201306');
If I use "https://adwords.google.com/" as Server, I recieve:
Uncaught exception 'OAuth2Exception' with message '{
"error" : "invalid_client"
}'
With the others servers, I recieve:
A PHP Error was encountered
Severity: Warning
Message:
SoapClient::SoapClient(https://sandbox.google.com/api/adwords/cm/v201306/CampaignService?wsdl): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
Filename: Lib/AdsSoapClient.php
or
A PHP Error was encountered
Severity: Warning
Message:
SoapClient::SoapClient(https://adwords-sandbox.google.com/api/adwords/cm/v201306/CampaignService?wsdl): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
Filename: Lib/AdsSoapClient.php
What should I do? I've read a lot in too many webs and I don't know how can I solve it
Thanks a lot!!
First of all you can find info (including the service endpoint url) about using the Analytics API as a test account here: https://developers.google.com/adwords/api/docs/test-accounts
Secondly, the readme states to use the following method to set your service:
$campaignService = $user->getCampaignService('v201306', 'https://adwords.google.com');
Lastly it seems the parameters you are using to initial the AdWordsUser object are a bit off, the readme also states the following:
$user = new AdWordsUser(NULL, NULL, NULL, $developerToken,
$applicationToken, $userAgent, $clientCustomerId, NULL, NULL,
$oauth2Info);

XMLRPC Zend_Http_Client_Adapter_Exception' with message 'Read timed out after 10 seconds

I've Googled everywhere but no one has posted a solution, they all say to set the timeout in the config but how do you do this?
How do I reset/override this setting from my XMLRPC client or server?
Here is what I'm trying:
$server = new Zend_XmlRpc_Client('http://127.0.0.1/xmlrpc');
$client = $server->getProxy();
// Increasing the timeout
$client->setConfig(array('timeout'=>30));
Here is the error:
Fatal error: Uncaught exception 'Zend_XmlRpc_Client_FaultException'
with message 'Method "setConfig" does not exist'
in /usr/share/php/libzend-framework-php/Zend/XmlRpc/Client.php:370
Trying to pass as arg:
$server = new Zend_XmlRpc_Client('http://127.0.0.1/xmlrpc', array('timeout'=>30));
Here is the error:
Catchable fatal error: Argument 2 passed to
Zend_XmlRpc_Client::__construct() must be an
instance of Zend_Http_Client
Found the solution and here it is:
$server = new Zend_XmlRpc_Client('http://127.0.0.1/xmlrpc');
// Get the HTTP Client used by the XMLRPC client
$http_client = $server->getHttpClient();
// Increasing the HTTP timeout
$http_client->setConfig(array('timeout'=>30));
$client = $server->getProxy();
One Line works for me as well:
$server = new Zend_XmlRpc_Client('http://127.0.0.1/xmlrpc');
// Get the HTTP Client used by the XMLRPC client and increasing the HTTP timeout
$server->getHttpClient()->setConfig(array('timeout'=>30));
$client = $server->getProxy();
Zend documentation specifies the configuration parameters that you are allowed to use. I would guess that you can simply increase the timeout from 10 seconds to 20 or 30. Whatever is appropriate for you.
$client = new Zend_Http_Client('http://example.org', array('timeout' => 30));
or:
$client->setConfig(array('timeout'=>30));
UPDATE - Zend_Http_Client is used by Zend_XmlRpc_Client. You can set and access the Zend_Http_Client via the Zend_XmlRpc_Client object.
$xmlrpc_client = new Zend_XmlRpc_Client('http://127.0.0.1/xmlrpc');
$xmlrpc_client->getHttpClient()->setConfig(array('timeout'=>30'));
I haven't tested this so I don't know that it will work but you can also pass in your own Zend_Http_Client object to a Zend_XmlRpc_Client object using the setHttpClient() method as described (rather arcanely) at the bottom of the Zend documentation page for Zend_XmlRpc_Client.
Whatever client you're using:
$client->getHttpClient()->setConfig(array('timeout'=>30));
where $client could be a Rest or Soap Client.
Also, one of the answers here has a minor error that causes pain:
client->getHttpClient()->setConfig(array('timeout'=>30')); - remove single quote after 30
Those answers are alright, though since Zend HTTP 2.0 (released in 2012 - see diff) it is :
$client->getHttpClient()->setOptions(array('timeout'=>30));

Categories