0

i'm using the same snippet of code both locally and online. At my localhost server i get HTTP status code of 200 and i have no problem. When i use the same piece of code at my webpage which i'm currently being hosted i get HTTP code of 0.

Here is the snippet i'm using for my HTTP call.

$curl = curl_init();

// Set the options
curl_setopt($curl,CURLOPT_URL, "http://xx.xxxxxxxxxx.xxx:xxxx/xx");

// This sets the number of fields to post
curl_setopt($curl,CURLOPT_POST, 1);

// This is the fields to post.
curl_setopt($curl,CURLOPT_POSTFIELDS, "Data");

//execute the post
$session = curl_exec($curl);
//Echo Http Response Code
$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);

//close the connection
curl_close($curl);

Any ideas?

6
  • Do you have curl installed on your server ? Commented Sep 7, 2015 at 12:43
  • I'm using curl for other purposes too and i had no problem with my server. So i guess that it's installed. Commented Sep 7, 2015 at 12:45
  • do this print curl_error($curl); Commented Sep 7, 2015 at 13:01
  • possible duplicate of stackoverflow.com/questions/10227879/… Commented Sep 7, 2015 at 13:01
  • If you connect with the server, then you can get a return code from it, otherwise it will fail and you get a 0. So if you try to connect to "www.google.com/lksdfk" you will get a return code of 400, if you go directly to google.com, you will get 302 (and then 200 if you forward to the next page... well I do because it forwards to google.com.br, so you might not get that), and if you go to "googlecom" you will get a 0 (host no found), so with the last one, there is nobody to send a code back. Commented Sep 7, 2015 at 13:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.