Server was unable to process request. ---> Index was out of range - php

I'm getting this error:
Fatal error: Uncaught SoapFault exception: [soap:Server] Server was unable to process request. ---> Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index in /var/www/index.php:30 Stack trace: #0 /var/www/index.php(30): SoapClient->__call() #1 {main} thrown in /var/www/index.php on line 30
My php-code is:
<?php
ini_set('error_log', '/var/www/php.log');
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
date_default_timezone_set('UTC');
include("include/connection.php");
$client = new SoapClient("https:// (LINK TO API) /ExternalApiWebService.asmx?wsdl", array('trace' => 1));
// **--** Login - START **--**
$LoginResult = $client->Login(
array("userName" => "USERNAME", "password" => "PASSWORD"
)
);
print "<pre>";
print_r ($LoginResult);
print "</pre>";
$SessionId = $LoginResult->LoginResult;
// **--** Login - END **--**
// **--** GetTriplogUnitPositions - START **--**
$GetTriplogUnitPositionsResult = $client->GetTriplogUnitPositions(
array("sessionId" => "".$SessionId.""
)
);
print "<pre>";
print_r ($GetTriplogUnitPositionsResult);
print "</pre>";
// **--** GetTriplogUnitPositions - END **--**
?>
Can anyone help me or give me a hint of whats wrong?

Related

When adding content to json file php error occurs

I'm learning php and started following a youtube video for a project.
When i accept contents from my json file and code it to add new contents to it, an error occurs.
Error-
Warning: Undefined variable $json_encode in /Users/montekkundan/Downloads/coding/php/newtodo.php on line 16
Fatal error: Uncaught Error: Value of type null is not callable in /Users/montekkundan/Downloads/coding/php/newtodo.php:16 Stack trace: #0 {main} thrown in /Users/montekkundan/Downloads/coding/php/newtodo.php on line 16
php code-
<?php
// echo "<pre>";
// var_dump($_POST);
// echo "</pre>";
$todoname = $_POST['todoname'] ?? "";
$todoname = trim($todoname);
if($todoname) {
$json = file_get_contents('todo.json');
$jsonArray = json_decode($json, true);
$jsonArray[$todoname] = ['completed' => false];
// echo "<pre>";
// var_dump($jsonArray);
// echo "</pre>";
file_put_contents('todo.json', $json_encode($jsonArray, JSON_PRETTY_PRINT)) ;
}
?>
Try to change
file_put_contents('todo.json', $json_encode($jsonArray, JSON_PRETTY_PRINT));
to file_put_contents('todo.json', json_encode($jsonArray, JSON_PRETTY_PRINT));
that's because you are trying to call json_encode variable, json_encode is not a variable.

php foreach loop with urls from file

I am trying to the status of urls which are stored in a text file
in my code i have:
$filestatus = file("urlsmartins_status.txt");
foreach ($filestatus as $filestate){
$filestatusurl = (file_get_contents("$filestate"));
$filestatusurlxml = new SimpleXMLElement ($filestatusurl);
print_r ($filestatusurlxml);
}
in the urlsmartin_status.txt i have 5 urls written
http://172.27.73.5:8080/api/service/
http://172.27.73.6:8080/api/service/
http://172.27.73.7:8080/api/service/
http://172.27.73.8:8080/api/service/
But when i execute the code i have the following result
PHP Warning: file_get_contents(http://172.27.73.5:8080/api/service/
): failed to open stream: HTTP request failed! HTTP/1.1 404 OK
PHP Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in ...
Stack trace:
#0 /opt/rh/httpd24/root/var/www/html/pub/martin.php(56): SimpleXMLElement->__construct('')
#1 {main}
thrown in /opt/rh/httpd24/root/var/www/html/pub/martin.php on line 56
What am i missing here?
Thanks
the problem here is that the lines in your file are not "XML", hence SimpleXMLElement cannot be instantiated.
I get the same error like this:
I managed to fix it via
$filedata = file_get_contents('urlsmartins_status.txt');
$urls = explode("\n", trim($filedata));
foreach($urls as $key => $url) {
$filestatusurl = file_get_contents("$url");
$filestatusurlxml = new SimpleXMLElement ($filestatusurl);
print_r ($filestatusurlxml);

Dropbox API for PHP gives error

I am trying to upload a file in chunks via Dropbox's API for PHP.
This is my code: This gives out the folowing error:
First few chunks are uploaded and then I get this error:-
Fatal error: Uncaught exception 'Dropbox\Exception_NetworkIO' with message 'Erro
r executing HTTP request: Failed to connect to api-content.dropbox.com port 443:
Connection refused' in /home/yashtk1/public_html/dropbox/Dropbox/Curl.php:69
Stack trace:
#0 /home/yashtk1/public_html/dropbox/Dropbox/Client.php(721): Dropbox\Curl->exec
()
#1 /home/yashtk1/public_html/dropbox/Dropbox/Client.php(602): Dropbox\Client->_c
hunkedUpload(Array, '`S\xCDb0\x80`\xA0\xD3\xB7\xEA\x07\xF1\xF7\xB4...')
#2 /home/yashtk1/public_html/dropbox/Dropbox/Client.php(437): Dropbox\Client->ch
unkedUploadContinue('jB2ZQWVyzMQgsX4...', 41943040, '`S\xCDb0\x80`\xA0\xD3\xB7\x
EA\x07\xF1\xF7\xB4...')
#3 /home/yashtk1/public_html/dropbox/Dropbox/RequestUtil.php(278): Dropbox\Clien
t->Dropbox\{closure}()
#4 /home/yashtk1/public_html/dropbox/Dropbox/Client.php(438): Dropbox\RequestUti
l::runWithRetry(3, Object(Closure))
#5 /home/yashtk1/public_html/dropbox/Dropbox/Client.php(381): Dropbox\Client->_u
ploadFileChunked('/ahmd1.zip', Object(Dropbox\WriteMode), Resource i in /home/ya
shtk1/public_html/dropbox/Dropbox/Curl.php on line 69
My script:-
<?php
echo "hi";
set_time_limit(0);
# Include the Dropbox SDK libraries
require_once "Dropbox/autoload.php";
use \Dropbox as dbx;
$appInfo = dbx\AppInfo::loadFromJsonFile("config");
$f = fopen("ahmd1.zip", "rb");
$dbxClient = new dbx\Client("Access code", "PHP-Example/1.0");
$mode = dbx\WriteMode::add();
$chunk = $dbxClient->uploadFileChunked("/ahmd1.zip", $mode, $f);
print_r($chunk);
//uploadFileChunked( string $path, Dropbox\WriteMode $writeMode, resource $inStream, integer|null $numBytes = null, integer|null $chunkSize = null );
fclose($f);
?>
Please can anyone point out the mistake ?

getting error of soap while using shipping validation

I am using ValidateShipment.php from purolator.com . I included all the wsdl files and included product key and password . But still getting error(s).
soap is already enabled.
you can see error here
Warning: Creating default object from empty value in /home/bandito/public_html/ValidateShipment.php on line 64
Warning: Creating default object from empty value in /home/bandito/public_html/ValidateShipment.php on line 71
Warning: Creating default object from empty value in /home/bandito/public_html/ValidateShipment.php on line 75
Warning: Creating default object from empty value in /home/bandito/public_html/ValidateShipment.php on line 82
Warning: Creating default object from empty value in /home/bandito/public_html/ValidateShipment.php on line 90
Warning: Creating default object from empty value in /home/bandito/public_html/ValidateShipment.php on line 95
Warning: Creating default object from empty value in /home/bandito/public_html/ValidateShipment.php on line 99
Warning: Creating default object from empty value in /home/bandito/public_html/ValidateShipment.php on line 101
Warning: Creating default object from empty value in /home/bandito/public_html/ValidateShipment.php on line 106
Fatal error: Uncaught SoapFault exception: [HTTP] Unauthorized in /home/bandito/public_html/ValidateShipment.php:110 Stack trace: #0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'https://webserv...', 'http://purolato...', 1, 0) #1 /home/bandito/public_html/ValidateShipment.php(110): SoapClient->__call('ValidateShipmen...', Array) #2 /home/bandito/public_html/ValidateShipment.php(110): SoapClient->ValidateShipment(Object(stdClass)) #3 {main} thrown in /home/bandito/public_html/ValidateShipment.php on line 110
and here is my php code-:
define("PRODUCTION_KEY", "**********************");
define("PRODUCTION_PASS", "***********");
define("BILLING_ACCOUNT", "**********");
define("REGISTERED_ACCOUNT", "**********");
function createPWSSOAPClient()
{
$client = new SoapClient( "wsdl/ShippingService.wsdl",
array (
'trace' => true,
'location' => "https://webservices.purolator.com/PWS/V1/Shipping/ShippingService.asmx",
'uri' => "http://purolator.com/pws/datatypes/v1",
'login' => PRODUCTION_KEY,
'password' => PRODUCTION_PASS
)
);
//Define the SOAP Envelope Headers
$headers[] = new SoapHeader ( 'http://purolator.com/pws/datatypes/v1',
'RequestContext',
array (
'Version' => '1.4',
'Language' => 'en',
'GroupID' => 'xxx',
'RequestReference' => 'Rating Example'
)
);
//Apply the SOAP Header to your client
$client->__setSoapHeaders($headers);
return $client;
}
/*********************************************************************************
Validate Shipment Example(s)
EXAMPLE 01:
1 piece shipment, 10lbs, Purolator Express Service on a Thermal 4x6 Label
*********************************************************************************/
//Create a SOAP Client for Example 01
$client = createPWSSOAPClient();
//Populate the Origin Information
$request->Shipment->SenderInformation->Address->Name = "Aaron Summer";
$request->Shipment->SenderInformation->Address->StreetNumber = "1234";
$request->Shipment->SenderInformation->Address->StreetName = "Main Street";
$request->Shipment->SenderInformation->Address->City = "Mississauga";
$request->Shipment->SenderInformation->Address->Province = "ON";
$request->Shipment->SenderInformation->Address->Country = "CA";
$request->Shipment->SenderInformation->Address->PostalCode = "L4W5M8";
$request->Shipment->SenderInformation->Address->PhoneNumber->CountryCode = "1";
$request->Shipment->SenderInformation->Address->PhoneNumber->AreaCode = "905";
$request->Shipment->SenderInformation->Address->PhoneNumber->Phone = "5555555";
//Populate the Desination Information
$request->Shipment->ReceiverInformation->Address->Name = "Aaron Summer";
$request->Shipment->ReceiverInformation->Address->StreetNumber = "2245";
$request->Shipment->ReceiverInformation->Address->StreetName = "Douglas Road";
$request->Shipment->ReceiverInformation->Address->City = "Burnaby";
$request->Shipment->ReceiverInformation->Address->Province = "BC";
request->Shipment->ReceiverInformation->Address->Country = "CA";
$request->Shipment->ReceiverInformation->Address->PostalCode = "V5C5A9";
$request->Shipment->ReceiverInformation->Address->PhoneNumber->CountryCode = "1";
$request->Shipment->ReceiverInformation->Address->PhoneNumber->AreaCode = "604";
$request->Shipment->ReceiverInformation->Address->PhoneNumber->Phone = "2982181";
//Future Dated Shipments - YYYY-MM-DD format
$request->Shipment->ShipmentDate = "YOUR_SHIPMENT_DATE_HERE";
//Populate the Package Information
$request->Shipment->PackageInformation->TotalWeight->Value = "10";
$request->Shipment->PackageInformation->TotalWeight->WeightUnit = "lb";
$request->Shipment->PackageInformation->TotalPieces = "1";
$request->Shipment->PackageInformation->ServiceID = "PurolatorExpress";
//Populate the Payment Information
$request->Shipment->PaymentInformation->PaymentType = "Sender";
$request->Shipment->PaymentInformation->BillingAccountNumber = BILLING_ACCOUNT;
$request->Shipment->PaymentInformation->RegisteredAccountNumber = REGISTERED_ACCOUNT;
//Populate the Pickup Information
$request->Shipment->PickupInformation->PickupType = "DropOff";
//Shipment Reference
$request->Shipment->TrackingReferenceInformation->Reference1 = "Reference For Shipment";
//Define the Shipment Document Type
$request->PrinterType = "Thermal";
//Define OptionsInformation
$request->OptionsInformation->Options->OptionIDValuePair->ID = "residentialsignaturedomestic";
$request->OptionsInformation->Options->OptionIDValuePair->Value = "true";
//Execute the request and capture the response
$response = $client->ValidateShipment($request);
print_r($response);
The $request class isn't declared. PHP is guessing it's an object and declaring it.
Try:
$request = new stdClass;
$request->Shipment = new stdClass;
$request->Shipment->ReceiverInformatio = new stdClass;
etc.
Place before the $request list starts.
//Populate the Origin Information
$request->Shipment->SenderInformation->Address->Name = "Aaron Summer";
Replace this line
$request->Shipment->SenderInformation->Address->Name = "Aaron Summer";
with
#$request->Shipment->SenderInformation->Address->Name = "Aaron Summer";

Uncaught SoapFault exception: [SOAP-ENV:Client] true in

i m using php soapclent, other calls are working good with this URL.here is the snap of the request to be passed.
not getting what is the problem ?
( ! ) Fatal error: Uncaught SoapFault exception: [SOAP-ENV:Client]
true in C:\wamp\www\ginger\createEditProfile.php:8 Stack trace: #0
C:\wamp\www\ginger\createEditProfile.php(8):
SoapClient->__soapCall('createEditProfi...', Array) #1 {main} thrown
in C:\wamp\www\ginger\createEditProfile.php on line 8
error_reporting(E_ALL);
$sc = new SoapClient("http://###.###.##.##/GingerIBE/services/consolidatedServicesBean.wsdl?wsdl", array('trace' => 1));
$params =array('targetProfile'=>array('loginId'=>'bhav1234','password'=>'test123','preferredHotel'=>'', 'customerId'=>'','firstName'=>'Bhavina','lastName'=>'Prajapati','customerType'=>'1','customerAccountGroup'=>'SH01','gender'=>'Female','dateOfBirth'=>'1987-11-01','emailId'=>'testing.abc#gmail.com','mobileNumber'=>'8866853905','phoneNumber'=>'8866853906','faxNumber'=>'8866853901','preferredModeOfContact'=>'','addressLine1'=>'some address line 1','addressLine2'=>'some address line 2','pinNumber'=>'','city'=>'Bangalore','state'=>'Karnataka','country'=>'India'));
$result = $sc->__soapCall('createEditProfile', array('parameters' => $params));
echo "<pre>";
print_r($result);
echo($sc->__getLastRequest());

Categories