1

For now i'm testing using file_get_content(url), but it's returning an error.

The request and response are in the same server:

warning: file_get_contents(https://192.168.1.15/adverts/locations): failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error in xxxxx

The Web-service returns a json object, so the function file_get_contents will receive a json.

I want to use cURL approach, but it doesn't work too.

So i thought to start ,fix this error first and get contents, and after try to debug why cURL is not working, since i'm getting content with this function

WS Response

{"status":"success","alerts":[],"content":{"types":[{"id":"P","description":"Permanent"},{"id":"C","description":"Contract"}]}}
Bruno
  • 131
  • 3
  • 17
  • http://stackoverflow.com/questions/9557945/include-failed-to-open-stream-no-such-file-or-directory – Smoke Oct 30 '15 at 10:02
  • Try var_dump(dirname(FILE)); or var_dump(realpath(dirname(FILE))); to debug – Smoke Oct 30 '15 at 10:02
  • https://192.168.1.15/adverts/locations is the link to the WS that responds with a json object! – Bruno Oct 30 '15 at 10:04
  • var_dump(dirname(FILE)) returns 192.168.1.15/adverts and var_dump(realpath(dirname(FILE))); returns bool(false), but if i run the service directly in the browser, this returns me the json response – Bruno Oct 30 '15 at 10:09
  • Why are you trying to read a JSON object like a stream ? The JSON is of type string, you try to treat it like a stream. – Kern Oct 30 '15 at 10:12
  • Into the json object goes a binary file! That's why! – Bruno Oct 30 '15 at 10:13
  • Can you print the JSON output you have in your browser please ? – Kern Oct 30 '15 at 10:16
  • @ Kern i've updated the post, so you can check there the json output – Bruno Oct 30 '15 at 12:51

1 Answers1

0

Try this with your webservice url and tell us if it throws some kind of Exception :

<?php 
    // create curl resource 
    $ch = curl_init(); 

    // set url 
    curl_setopt($ch, CURLOPT_URL, "192.168.1.15/adverts/locations"); 

    //return the transfer as a string 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

    // $output contains the output string 
    $output = curl_exec($ch); 

    // close curl resource to free up system resources 
    curl_close($ch);

Are you sure you can use HTTPS with your server ? Have you the right settings and certificates ?

Kern
  • 858
  • 1
  • 8
  • 24