1
Vote

Error Occured During Request

description

I am trying to connect to the API service
        try
        {
            $svc = new ServiceDataModel();
            $response = $svc->Execute('Users(1061)/?$format=json&$select=Email');
            echo $response->Result;
        }
        catch(DataServiceRequestException $ex)
        {
            echo 'Error: while running the query ' . $ex->Response->getQuery();
            echo "<br/>";
            echo '<strong>'.$ex->Response->getError().'</strong>';
        }
        catch (ODataServiceException $e)
        {
            echo "Error:" . $e->getError() . "<br>" . "Detailed Error:" . $e->getDetailedError();
        }
but it gives me an error of 401 - Unauthorize user.
so on the framework/Context/ObjectContext.php I modify
//Line 249
$this->HttpProxy = new HttpProxy('https://service.com','80','username','password');
And when I try to load the request again, it so slow and gives me an error of
__Error: while running the query  https://service.com/Data/OData.svc/Users/?$format=json&$select=Email
Error occured during request for https://service.com/Data/OData.svc/Users/?$format=json&$select=Email: Recv failure: Connection was reset__
But when I try to use cURL as direct request it is working fine.

Sample
  $username="username";
        $password="password";
        $url = 'https://service.com/Data/OData.svc/Users/?$format=json&$select=Email';

        //  Initiate curl
        $ch = curl_init();                              //open connection
        curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        $json_result = curl_exec($ch);
        curl_close($ch);

        // Will dump a beauty json :3
        $result = json_decode($json_result, true);
        var_dump($result['Email']);
I can't really find what is wrong with the request. Cause if I try to access it thru browser it gives data.

Anyone knows what cause of the error? Thanks

comments