Error: Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR - php

I tried to convert a pdf file to an image.
I check this website, and follow all step instructions.
1.obtain an api license key
2.download the API Class
3.Deploy the php file
4.create my pdf file
But when i run my file happens this error:
ERROR
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://apis.pdfaid.com/pdfaidservices/Service1.svc?wsdl' : failed to load external entity "http://apis.pdfaid.com/pdfaidservices/Service1.svc?wsdl" in C:\xampp\htdocs\Web_V2\PdfaidServices.php:128 Stack trace: #0 C:\xampp\htdocs\Web_V2\PdfaidServices.php(128): SoapClient->SoapClient('http://apis.pdf...', Array) #1 C:\xampp\htdocs\Web_V2\teste_1.php(32): Pdf2Jpg->Pdf2Jpg() #2 {main} thrown in C:\xampp\htdocs\Web_V2\PdfaidServices.php on line 128
The part of the bold code is where raises the error
Could anyone help me please?
I would forever gratefull.
This is my file
<?php
include 'PdfaidServices.php';
$myPdf2Jpg = new Pdf2Jpg();
$myPdf2Jpg->apiKey = "xxxxxxxxxx";
$myPdf2Jpg->inputPdfLocation = "pdf_file.pdf";
$myPdf2Jpg->outputZipLocation = "UploadedPdf/pdf2jpg.zip";
$myPdf2Jpg->outputImageFormat = ".jpg";
$myPdf2Jpg->imageQuality = 50;
$result = $myPdf2Jpg->Pdf2Jpg();
?>
This is API Class PdfaidServices.php where erros happens
<?php
class Xps2PdfConverter
{
public $apiKey = "";
public $inputXpsLocation = "";
public $outputPdfLocation = "";
public $pdfAuthor = "";
public $pdfTitle = "";
public $pdfSubject = "";
public $pdfKeywords = "";
function Xps2PdfConvert()
{
if($this->apiKey == "")
return "Please specify ApiKey";
if($this->outputPdfLocation == "")
return "Please specify location to save output Pdf";
if($this->inputXpsLocation == "")
return "Please specify input XPS file Location";
else
{
$fileStream = file_get_contents($this->inputXpsLocation);
}
$parameters = array("FileByteStream" => $fileStream);
$wsdl = "http://apis.pdfaid.com/pdfaidservices/Service1.svc?wsdl";
$endpoint = "http://apis.pdfaid.com/pdfaidservices/Service1.svc";
$option=array('trace'=>1);
$client = new SoapClient($wsdl, $option);
$headers[] = new SoapHeader('http://tempuri.org/', 'apikey', $this->apiKey);
$headers[] = new SoapHeader('http://tempuri.org/', 'pdfTitle', $this->pdfTitle);
$headers[] = new SoapHeader('http://tempuri.org/', 'pdfAuthor', $this->pdfAuthor);
$headers[] = new SoapHeader('http://tempuri.org/', 'pdfSubject', $this->pdfSubject);
$headers[] = new SoapHeader('http://tempuri.org/', 'pdfKeywords', $this->pdfKeywords);
$headers[] = new SoapHeader('http://tempuri.org/', 'responseResult', "test");
$client->__setSoapHeaders($headers);
$result = $client->Xps2Pdf($parameters);
$clientResponse = $client->__getLastResponse();
if($clientResponse == "APINOK")
return "API is not Valid";
if($clientResponse == "NOK")
return "Error Occured";
else
{
$fp = fopen($this->outputPdfLocation, 'wb');
fwrite($fp, $result->FileByteStream);
fclose($fp);
return "OK";
}
}
}
class Pdf2Jpg
{
public $apiKey = "";
public $outputImageFormat = "";
public $inputPdfLocation = "";
public $outputZipLocation = "";
public $imageQuality = 50;
function Pdf2Jpg()
{
if($this->apiKey == "")
return "Please specify ApiKey";
if($this->outputImageFormat == "")
return "Please specify Output Image Format";
if($this->outputZipLocation == "")
return "Please specify Output Zip File Location";
if($this->inputPdfLocation == "")
return "Please specify input Pdf file Location";
else
{
$fileStream = file_get_contents($this->inputPdfLocation);
}
$parameters = array("FileByteStream" => $fileStream);
$wsdl = "http://apis.pdfaid.com/pdfaidservices/Service1.svc?wsdl";
$endpoint = "http://apis.pdfaid.com/pdfaidservices/Service1.svc";
$option=array('trace'=>1);
$client = new SoapClient($wsdl, $option);
$headers[] = new SoapHeader('http://tempuri.org/', 'apikey', $this->apiKey);
$headers[] = new SoapHeader('http://tempuri.org/', 'outputFormat', $this->outputImageFormat);
$headers[] = new SoapHeader('http://tempuri.org/', 'imageQuality', $this->imageQuality);
$headers[] = new SoapHeader('http://tempuri.org/', 'responseResult', "test");
$client->__setSoapHeaders($headers);
$result = $client->Pdf2Jpg($parameters);
$clientResponse = $client->__getLastResponse();
if($clientResponse == "APINOK")
return "API is not Valid";
if($clientResponse == "NOK")
return "Error Occured";
else
{
$fp = fopen($this->outputZipLocation, 'wb');
fwrite($fp, $result->FileByteStream);
fclose($fp);
return "OK";
}
}
}
?>
Please!! Someone can help me please?

Works fine from my machine. Do you have network connectivity to the said wsdl? What happens when you stick that wsdl URL in a browser?

Related

Que API calls in function

I'm doing two calls to an API. The only thing that differ the two calls is the URL. What i basically wonder is how i can structure this a little (or alot) better? Maybe run them after each other in a que? Sometimes the second calls returns a "critical error" on the Wordpress page where it gets called.
Any suggestions?
private $oauth_Key = 'xxx';
private $oauth_consumer = 'xxx';
private $api_url = 'xxx';
private $cat_url = 'xxx';
try {
$oauth = new OAuth($this->oauth_Key, $this->oauth_consumer, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_AUTHORIZATION);
$oauth->fetch($this->api_url);
$response_info = $oauth->getLastResponseInfo();
header("Content-Type: {$response_info["content_type"]}");
$res = $oauth->getLastResponse();
$oauth2 = new OAuth($this->oauth_Key, $this->oauth_consumer, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_AUTHORIZATION);
$oaut2->fetch($this->cat_url);
$response_info2 = $oauth2->getLastResponseInfo();
header("Content-Type: {$response_info2["content_type"]}");
$res2 = $oauth2->getLastResponse();
} catch(OAuthException $e) {
echo "Exception caught!\n";
echo "Response: ". $e->lastResponse . "\n";
}
Just figured it out. Re structured the code a bit. See below:
private $oauth_Key = 'xxx';
private $oauth_consumer = 'xxx';
private $api_url = 'xxx';
private $cat_url = 'xxx';
try {
$oauth = new OAuth($this->oauth_Key, $this->oauth_consumer, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_AUTHORIZATION);
$oauth->fetch($this->api_url);
$response_info = $oauth->getLastResponseInfo();
header("Content-Type: {$response_info["content_type"]}");
$res = $oauth->getLastResponse();
$oauth2 = new OAuth($this->oauth_Key, $this->oauth_consumer, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_AUTHORIZATION);
$oauth2->fetch($this->cat_url);
$response_info2 = $oauth2->getLastResponseInfo();
header("Content-Type: {$response_info2["content_type"]}");
$res2 = $oauth2->getLastResponse();
} catch(OAuthException $e) {
echo "Exception caught!\n";
echo "Response: ". $e->lastResponse . "\n";
}

CURL - sending variables with GET not working

I want to send the request to another site with GET request and should return a string value. I am using the following cURL code to achieve this but its getting failed.
$user = 'username';
$password = 'password';
$sender_id = 'myid';
$sender_mobile = mobile number;
$message_text = 'Hi Testing SMS';
$priority = 'ndnd';
$sms_type = 'normal';
$redirect_link = "http://bhashsms.com/api/sendmsg.php?user=$user&pass=$password&sender=$sender_id&phone=$sender_mobile&text=$message_text&priority=$priority&stype=$sms_type";
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$redirect_link);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$output=curl_exec($ch);
if($output == false)
{
echo "Error Number:".curl_errno($ch)."<br>";
echo "Error String:".curl_error($ch);
}
$info = curl_getinfo($ch);
curl_close($ch);
But if i use the header its sending successfully the following is using header
$user = 'username';
$password = 'password';
$sender_id = 'myid';
$sender_mobile = mobile number;
$message_text = 'Hi Testing SMS';
$priority = 'ndnd';
$sms_type = 'normal';
$redirect_link = "http://bhashsms.com/api/sendmsg.php?user=$user&pass=$password&sender=$sender_id&phone=$sender_mobile&text=$message_text&priority=$priority&stype=$sms_type";
header("Location:$redirect_link");
where am I going wrong!!!
You have an error on $sender_mobile = mobile number; should be like this $sender_mobile = 'mobile number';

CRM dynamic "an error occurred when verifying security for the message"

I am tring to access http://xxxxxxxxxxx/CRM2011/XRMServices/2011/Organization.svc?wsdl
I can able to see functions list. means i can access to webservice. But while i tring to write data using function create it through "an error occurred when verifying security for the message" my code is below
<?php
date_default_timezone_set("Asia/Kolkata");
ini_set("soap.wsdl_cache_enabled", "0");
$location = "http://182.18.175.29/CRM2011/XRMServices/2011/Organization.svc?wsdl";
$config['Username'] = 'xxxxxxx';
$config['Password'] = 'xxxxxx';
$config['soap_version'] = SOAP_1_2;
$config['trace'] = 1; // enable trace to view what is happening
$config['use'] = SOAP_LITERAL;
$config['style'] = SOAP_DOCUMENT;
$config['exceptions'] = 0; // disable exceptions
$config["cache_wsdl"] = WSDL_CACHE_NONE; // disable any caching on the wsdl, encase you alter the wsdl server
$config["features"] = SOAP_SINGLE_ELEMENT_ARRAYS;
include_once 'ntlmSoap.php';
$client = new NTLMSoapClient($location, $config);
print('<pre>');
print_r($client->__getFunctions());
$HeaderSecurity = array("UsernameToken" => array("Username" => 'xxxxxx', "Password" => 'xxxxxx'));
$header[] = new SoapHeader($location, "Security", $HeaderSecurity);
$client->__setSoapHeaders($header);
$params = array(
"bmw_firstname" => "test",
"bmw_lastname" => "test"
);
try {
$response = $client->__soapCall("Create", $params);
var_dump($response);
} catch (Exception $e) {
print_r($e);
}
// display what was sent to the server (the request)
echo "<p>Request :" . htmlspecialchars($client->__getLastRequest()) . "</p>";
// display the response from the server
echo "<p>Response:" . htmlspecialchars($client->__getLastResponse()) . "</p>";

sending bulk sms stops in middle

Guys i have an issue in the following code. I need to send bulk sms to 24,000 mobile numbers. But if i send it after 150 number send it shows me an Internal server error and stop send other following numbers. Kindly go through the code given below and reply the positive code that can really help me.
<?php
//Code using fopen
//Change your configurations here.
//---------------------------------
$username = "username";
$api_password = "api_password";
$sender = "sender";
$domain = "domain";
$priority = "1";// 1-Normal,2-Priority,3-Marketing
$method = "POST";
//---------------------------------
for ($i = 0; $i < $var; $i++) {
if (isset($_REQUEST['send'])) {
$mobile = $explode_num[$i];
$lenthof_number = strlen($mobile);
if ($lenthof_number >= 10) {
$message = $_REQUEST['message'];
$username = urlencode($username);
$password = urlencode($api_password);
$sender = urlencode($sender);
$message = urlencode($message);
$parameters = "username=$username&api_password=$api_password&sender=$sender&to=$mobile&message=$message&priority=$priority";
if ($method == "POST") {
$opts = array(
'http' => array(
'method' => "$method",
'content' => "$parameters",
'header' => "Accept-language: en\r\n" .
"Cookie: foo=bar\r\n"
)
);
$context = stream_context_create($opts);
$fp = fopen("http://$domain/pushsms.php", "r", false, $context);
} else {
$fp = fopen("http://$domain/pushsms.php?$parameters", "r");
}
$response = stream_get_contents($fp);
fpassthru($fp);
fclose($fp);
if ($response == "")
echo "Process Failed, Please check domain, username and password.";
else
echo "$response";
}//third if
}//second if
}//first if
}//main for
?>
Probably your page exeeded the max execution time. Put following code on top of page and try:
ini_set("memory_limit","128M");
//ini_set("memory_limit","256M");
//this sets it unlimited
ini_set("max_execution_time",0);
Add this on the top of your PHP Script
<?php
set_time_limit(0);

Php gcal class Not working

Iam using a php class to add event to google calender.But the class return an error when loading index.php page.
This is the code in index.php page here iam calling class:
<?php
require_once('gcal.class.php');
$g = new gcal('test#gmail.com','test123$');
$cal_url = 'https://www.google.com/calendar/feeds/test#gmail.com/private-01d281d910a2622c8c2f5899690b9eb5/basic';
$eTitle = 'test event'; $eDesc = 'Another Test'; $eAuthorName = 'Justin Burger'; $eAuthorEmail = 'justin#loudisrelative.com'; $eLocation = 'LIR Offices'; $eStartTime = date('c'); $eEndTime = date('c',strtotime("+1 hour"));
//Adding an event.
$g->addEvent($cal_url,$eTitle, $eDesc, $eAuthorName, $eAuthorEmail,$eLocation,$eStartTime, $eEndTime);
?>
And this is the gcal.class.php code :
<?php
require_once('HTTP/Request.php');
class gcal{
/** Google Auth Token, used to authorize add functions*/
private $token;
/** Users Email Address (notice, password is not stored) */
private $email;
function __construct($email, $password){
$this->login($email,$password);
$this->email = $email;
}
public function addEvent($cal_url,$eTitle, $eDesc, $eAuthorName, $eAuthorEmail,$eLocation,$eStartTime, $eEndTime){
/* Make sure we send ONLY valid XML. */
$eTitle = htmlentities($eTitle);
$eDesc = htmlentities($eDesc);
$eAuthorName = htmlentities($eAuthorName);
$eAuthorEmail = htmlentities($eAuthorEmail);
$eLocation = htmlentities($eLocation);
$eStartTime = htmlentities($eStartTime);
$eEndTime = htmlentities($eEndTime);
$xml = "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005'>
<category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/g/2005#event'></category>
<title type='text'>{$eTitle}</title>
<content type='text'>{$eDesc}</content>
<author>
<name>{$eAuthorName}</name>
<email>{$eAuthorEmail}</email>
</author>
<gd:transparency value='http://schemas.google.com/g/2005#event.opaque'></gd:transparency>
<gd:eventStatus
value='http://schemas.google.com/g/2005#event.confirmed'>
</gd:eventStatus>
<gd:where valueString='{$eLocation}'></gd:where>
<gd:when startTime='{$eStartTime}'
endTime='{$eEndTime}'></gd:when>
</entry>";
$http = new HTTP_Request($cal_url,array('allowRedirects' => true));
$http->setMethod('POST');
$http->addHeader('Host','www.google.com');
$http->addHeader('MIME-Version','1.0');
$http->addHeader('Accept','text/xml');
$http->addHeader('Content-type','application/atom+xml');
$http->addHeader('Authorization','GoogleLogin auth=' . $this->token);
$http->addHeader('Content-length',strlen($xml));
$http->addHeader('Cache-Control','no-cache');
$http->addHeader('Connection','close');
$http->setBody($xml);
$http->sendRequest();
switch($http->getResponseCode()){
case 201: case 200:
return true;
break;
default:
throw new Exception('Error Adding Google Cal Event. Response From Google:' . $http->getResponseBody(), $http->getResponseCode());
return false;
break;
}
}
public function getCalendarList(){
$url = 'http://www.google.com/calendar/feeds/' . $this->email;
$http = new HTTP_Request($url,array('allowRedirects' => true));
$http->addHeader('Authorization','GoogleLogin auth=' . $this->token);
$http->setMethod('GET');
$http->sendRequest();
$xml = new SimpleXMLElement($http->getResponseBody());
$calendars = array();
foreach ($xml->entry as $cal){
foreach($cal->link as $key=>$link){
$linkSets = array();
$links = $link->attributes();
$links = (array) $links;
foreach($links as $l){
$linkSets[] = array('rel'=>$l['rel'],
'type'=>$l['type'],
'href'=>$l['href']);
}
}
$calendars[] = array('id'=>strval($cal->id),
'published'=>strval($cal->published),
'updated'=>strval($cal->updated),
'title'=>strval($cal->title),
'authorName'=>strval($cal->author->name),
'authorEmail'=>strval($cal->author->email),
'links'=>$linkSets);
}
return $calendars;
}
private function login($email, $password){
$url = 'https://www.google.com/accounts/ClientLogin';
$http = new HTTP_Request('https://www.google.com/accounts/ClientLogin',
array('allowRedirects' => true));
$http->setMethod('POST');
$http->addPostData('Email', $email);
$http->addPostData('Passwd', $password);
$http->addPostData('source', 'example-test-2');
$http->addPostData('service', 'cl');
$http->addPostData('accountType', 'HOSTED_OR_GOOGLE');
$http->sendRequest();
switch($http->getResponseCode()){
case 403:
throw new Exception('Google Auth Failed',403);
break;
case 200: case 201:
$this->token = $this->extractAuth($http->getResponseBody());
return true;
break;
default:
throw new Exception('Unknown Google Auth Failure',$http->getResponseCode());
break;
}
}
private function extractAuth($body){
$st = strpos($body,'Auth=');
$token = trim(substr($body,($st+5)));
return $token;
}
}
?>
Then iam taking this in browser it displays error:
Warning: require_once(HTTP/Request.php) [function.require-once]: failed to open stream: No such file or directory in E:\wamp\www\gcal\gcal.class.php on line 2
Fatal error: require_once() [function.require]: Failed opening required 'HTTP/Request.php' (include_path='.;C:\php\pear') in E:\wamp\www\gcal\gcal.class.php on line 2
What is the problem in my code?
When i downloading the class from google code they said that please make sure you have both installed before use (for example: pear install Net and pear install HTTP) .
I dont know how to do this?Give me a solution.
You need to install HTTP_Request package in order to make it work. The package can be found here
See here for installation
Hope it helps
First, check in your 'php' folder if 'PEAR' folder exists. If doesn't then install PEAR (instruction: http://pear.php.net/manual/en/installation.php).
If so check in 'php.ini' if parameter 'include_path' has absolute path to 'PEAR' folder (e.g. on Windows: include_path = ".;C:\xampp\php\PEAR")
Regards
Bronek

Categories