When I try to send request to the server in localhost I receive this message :
Error: call to URL
https://wasl.elm.sa/WaslPortalWeb/rest/DriverRegistration/send failed
with status 200, response {"resultCode":503,"resultMessage":"Yakeen
Failure: The ID Is Not Found at
NIC","referenceNumber":0,"valid":false}, curl_error , curl_errno 0
On the live server I receive this message :
string(171) "{"apiKey":"My api
key","captainIdentityNumber":"12355567897","dateOfBirth":"15-07-1400","emailAddress":"mo#mo.com","mobileNumber":"966508060095"}"
Error: call to URL
https://wasl.elm.sa/WaslPortalWeb/rest/DriverRegistration/send failed
with status 0, response , curl_error Unknown SSL protocol error in
connection to wasl.elm.sa:443 , curl_errno 35
I use this script to make the request:
<?php
//driver registartion url
$url = "https://wasl.elm.sa/WaslPortalWeb/rest/DriverRegistration/send";
$data=["apiKey"=>"My apikey","captainIdentityNumber"=>"1234567897","dateOfBirth"=>"15-07-1400","emailAddress"=>"mo#mo.com","mobileNumber"=>"966508060095"];
$content = json_encode($data);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER,false);
curl_setopt($curl, CURLOPT_HTTPHEADER,array("Content-type: application/json"));
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
var_dump($content);
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 201 ) {
die("Error: call to URL $url failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl));
}
curl_close($curl);
$response = json_decode($json_response, true);
var_dump($response);
?>
my api key it's correct one given by the server owner
This is related to Wasl portal, it is not related to curl or connection errors.
You have to contact the portal admins because it is API specific error.
Related
I am working on PHP and Salesforce integration and I want to update records using PHP.
I want to update records in Salesforce when clicking on the Button "Follow up".
And also try the below code.
function update_account($id, $followup, $instance_url, $access_token) {
$url = "$instance_url/services/data/v20.0/sobjects/Contact/$id";
$content = json_encode(array("shivendra__FollowUp__c" => $followup));
echo $content;
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_HTTPHEADER,
array("Authorization: OAuth $access_token",
"Content-type: application/json"));
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH");
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 204 ) {
die("Error: call to URL $url failed with status $status, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl));
}
echo "<b>update_contact function</b>";
echo "HTTP status $status updating Contact<br/><br/>";
curl_close($curl);
}
But getting an error:
{"shivendra__FollowUp__c":null}
[{"errorCode":"METHOD_NOT_ALLOWED","message":"HTTP Method 'PATCH' not allowed. Allowed are HEAD,GET,POST"}]
Error: call to URL https://shivendra-dev-ed.my.salesforce.com/services/data/v20.0/sobjects/Contact/ failed with status 405, curl_error , curl_errno 0
Try the post method with cURL, similar to this:
curl_setopt($ch, CURLOPT_POST, 1);
why some url with json content return null on php function get page content?
i used these ways :
file_get_content
curl
http_get
but return null . but when page open with browser json content show on browser ?? anyone can help me?
$url = 'https://pardakht.cafebazaar.ir/devapi/v2/api/validate/com.pdgroup.insta/inapp/coin_follow_1/purchases/324234235/?access_token=9IaRpdmQzFppJMabLHbHyzBaQnm8bM';
$result = file_get_content($url);
return null but in browser show
{"error_description": "Access token has expired.", "error": "invalid_credentials"}
It returns the following:
failed to open stream: HTTP request failed! HTTP/1.1 401 UNAUTHORIZED
So, you have to be authorized.
You ca play with this code snippet (I can't test since token expired again):
<?php
$access_token = "s9spZax2Xrj5g5bFZMJZShbMrEVjIo"; // use your actual token
$url = "https://pardakht.cafebazaar.ir/devapi/v2/api/validate/com.pdgroup.insta/inapp/coin_follow_1/purchases/324234235/";
// Solution with file_get_contents
// $content = file_get_contents($url . "?access_token=" . $access_token);
// echo $content;
// Solution with CURL
$headers = array(
"Accept: application/json",
"Content-Type: application/json",
"Authorization: Basic " . $access_token
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, $url); // . $params - if you need some params
curl_setopt($ch, CURLOPT_POST, false);
// curl_setopt($ch, CURLOPT_USERPWD, $userPwd);
$result = curl_exec($ch);
$ch_error = curl_error($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($ch_error) {
throw new Exception("cURL Error: " . $ch_error);
}
if ($info["http_code"] !== 200) {
throw new Exception("HTTP/1.1 " . $info["http_code"]);
}
echo $result;
I am trying to send JSON data to another php file for now for learning purpose (actually meant to be sent to a react-native app) but this returns an error saying
Error: call to URL http://localhost/hhh.php failed with status 200, response , curl_error , curl_errno 0
if($cliSeq==0)
{
$welcomearr= array("welcome");
$url = "http://localhost/hhh.php";
$welcomeJSON = json_encode($welcomearr);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER,
array("Content-type: application/json"));
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $welcomeJSON);
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 201 ) {
die("Error: call to URL $url failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl));
}
curl_close($curl);
$response = json_decode($json_response, true);
}
i'm trying to add a new user to redmine using REST api :
<?php
$service_url = "https://pmt.proxym-it.tn?key=9ed507d365eaa598a0f134c3eeb3efa062eb72de&method=POST&format=json";
$curl = curl_init($service_url);
$curl_post_data = array('user' => array("lastname"=>'Lachtar',"firstname"=>'Abdelfetteh',"login"=>'fetteh',"mail"=>'abdelfett ehlachtar#yahoo.fr',"password"=>'secret'));
$curl_post_data = json_encode($curl_post_data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$curl_response = curl_exec($curl);
if ($curl_response === false) {
$info = curl_getinfo($curl);
curl_close($curl);
die('error occured during curl exec. Additioanl info: ' . var_export($info));
}
curl_close($curl);
$decoded = json_decode($curl_response);
if (isset($decoded->response->status) && $decoded->response->status == 'ERROR') {
die('error occured: ' . $decoded->response->errormessage);
}
echo 'response ok!';
var_export($decoded);
?>
but the response returned is null.
when using
http://username:password#localhost:9000
as url, its showing same error response ok!NULL but in redmine log its showing the following
Parameters: {"{\"user\":{\"lastname\":\"test\",\"firstname\":\"rest\",\"login\":\"rest\",\"mail\":\"rest#test.com\",\"password\":\"12345678\"}}"=>"[FILTERED]", "method"=>"POST"}
Current user: anonymous
Filter chain halted as :check_if_login_required rendered or redirected
Completed 401 Unauthorized in 3.3ms (ActiveRecord: 0.3ms)
We are updating our system and the old IPNs need to be processed differently. However, I cannot change the original IPN send-to addresses. So I have to "bounce" the IPN message off of old_IPNProcessor.php and forward it to new_IPNProcessor.php. I cannot modify old_IPNProcessor.php for technical reasons that go beyond the scope of this question.
From what I have read, I have to use cURL to accomplish this. I have seen some code for this, but I am unsure as to how it's implemented. For instance, the $post var in the code below (from https://stackoverflow.com/a/6213693/1390395) is the raw json straight from PayPal. Does it have to be in a PHP array for this to work?
function forwardIPN($post){
$url = "new_IPNProcessor.php";
// $post is the ipn message from PayPal
$content = $post;
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER,
array("Content-type: application/json"));
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 201 ) {
die("Error: call to URL $url failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl));
}
curl_close($curl);
$response = json_decode($json_response, true);
}