I am getting this Curl Code error , anyone can help me regarding this issue please

http://www.opencartgulf.com/test.php
<?php

$url ='http://212.76.95.85:8844/CreateHWB.aspx?from=RYD&to=DMM&shipid=1223456789&shipssn=0&shipname=mohamad&shipphone=098765&shipcity=riyadh&shipaddress=Riyadh-Olayia&rcvssn=0&rcvname=toto&rcvphone=0546445819&rcvcity=dammam&rcvaddress=dammam-Raka%20&pkgdesc=IPHONE&codvalue=1700&pcs=1&customerno=110004&weight=3&passcode=TestPassword&refno=0';
$ch = curl_init();
  $timeout = 0;
  curl_setopt ($ch, CURLOPT_URL, $url);
  curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

  curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
  curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  $response_data= curl_exec($ch);
  if (!$response_data){
           die(curl_error($ch));
  }
  curl_close($ch);
  //Send data for verification
         $object = json_decode($response_data);
         $response = $object->response_code;
  if($response==100) {
   
   
  }
?>

Open in new window

Hamdan ShafiqPHP Full Stack DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NerdsOfTechTechnology ScientistCommented:
I'm showing data returning without error unless the number is an error code?:

[["009611691"]]

Open in new window


What is the expected result?
0
Julian HansenCommented:
There are a few things going on here

1. Absence of code tags. Please use them they make your code more readable (select code then click CODE in the toolbar) [ I have done this for you]

2. Your URL is throwing this error
Error: "Failed to connect to 212.76.95.85 port 8844: Connection refused" - Code: 7

Open in new window

Fairly self explanatory - the receiving server does not want to talk to you

3. As with NerdsOfTech - I implemented your code and it works fine - it returns this
[["009611712"]]

Open in new window

Which is a valid JSON response.

Your code however seems to be expecting something else. Specifically
$object = json_decode($response_data);
$response = $object->response_code;

Open in new window

Is expecting an object with a property response_code - when the actual return is an array of arrays
Array
(
    [0] => Array
        (
            [0] => 009611719
        )

)

Open in new window

0
Hamdan ShafiqPHP Full Stack DeveloperAuthor Commented:
<?php

$url ='http://212.76.95.85:8844/CreateHWB.aspx?from=RYD&to=DMM&shipid=1223456789&shipssn=0&shipname=mohamad&shipphone=098765&shipcity=riyadh&shipaddress=Riyadh-Olayia&rcvssn=0&rcvname=toto&rcvphone=0546445819&rcvcity=dammam&rcvaddress=dammam-Raka%20&pkgdesc=IPHONE&codvalue=1700&pcs=1&customerno=110004&weight=3&passcode=TestPassword&refno=0';
$ch = curl_init();
  $timeout = 0;
  curl_setopt ($ch, CURLOPT_URL, $url);
  curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

  curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Accept: application/json'
));
  curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  $response_data= curl_exec($ch);
  if (!$response_data){
           die(curl_error($ch));
  }
  curl_close($ch);
  //Send data for verification
 $object = json_decode($response_data);
$status = $object->response_code;
?>
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Julian HansenCommented:
@Hamdan - you seem to have posted code without tags again - please could you use them.

It is also not clear what your intention was with your last post?
0
Hamdan ShafiqPHP Full Stack DeveloperAuthor Commented:
how can send request and get responsive for
http://212.76.95.85:8844/hwbinfo.aspx?hwb_no=9603116
0
Hamdan ShafiqPHP Full Stack DeveloperAuthor Commented:
please run this url in browser and check
http://212.76.95.85:8844/hwbinfo.aspx?hwb_no=9603116
i want to read the data by this url but number could be changed

Kindly help me regarding this issue.
0
Julian HansenCommented:
That returns an array of values.
This code
<?php

$url ='http://212.76.95.85:8844/hwbinfo.aspx?hwb_no=9603116';
$ch = curl_init();
  $timeout = 0;
  curl_setopt ($ch, CURLOPT_URL, $url);
  curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

  curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
  curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  $response_data= curl_exec($ch);
  if (!$response_data){
           die(curl_error($ch));
  }
  curl_close($ch);
  //Send data for verification
  $object = json_decode($response_data);
  echo "<pre>" . print_r($object, true) . "</pre>";

Open in new window


Returns these values
Array
(
    [0] => Array
        (
            [0] => 009603116
            [1] => ORG
            [2] => Under Process
            [3] => 12/20/2016 10:11:41 AM
            [4] => RYD
            [5] => Riyadh
            [6] => الرياض
            [7] => DMM
            [8] => Dammam
            [9] => الدمام
            [10] => 1
            [11] => 
            [12] => 
            [13] => ZJL0012
            [14] => Shipment Picked-up from sender
            [15] => تم استلام الشحنة من العميل المرسل
        )

)

Open in new window

Which value are you looking for?
Will the return always contain the same values in the same order?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Chris StanyonWebDevCommented:
The 2 URLs you've posted return different results - but they both return an array containing an array.

To get at the ID you want, you need to access the array's numerical index:

$object = json_decode($response_data);
$status = $object[0][0];

Open in new window

This will access the first element [0] of the first array [0], which in the results of both your URLs would be the ID.
0
Hamdan ShafiqPHP Full Stack DeveloperAuthor Commented:
hello,
code working fine on local pc.
but online is not working
http://www.opencartgulf.com/test.php
0
Julian HansenCommented:
This is not a coding problem -
Failed to connect to 212.76.95.85 port 8844: Connection refused

The remote server is refusing the connection - you need to find out from them why - your IP might be black listed or any number of other issues - but we can't solve this one with code.
0
Hamdan ShafiqPHP Full Stack DeveloperAuthor Commented:
Thank you so much  Julian Hansen
0
Julian HansenCommented:
You are welcome.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Curl

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.