나는 내가 개발하고있는 api와 클라이언트를 laravel에서 가지고 있는데, 나는 gui를 사용하여 api에 연결하려고 시도 할 때 18 오류가 발생합니다. 내 API를 컨트롤러에서Guarre curl error 18 with Laravel
나는이 있습니다
public function index()
{
$users = User::orderBy('username', 'asc');
return Response::json(array(
'error' => false,
'users' => $users->get()->toArray()),
200
);
}
을 내가 할 경우 컬 --user [email protected] : 비밀번호 http://myapi.api/api/v1/users
나는 내 콘솔에 정확하게 필요한 정보를 얻을 :
{"error":false,"users":[{"id":"1","firstname":"","lastname":"","username":"[email protected]","created_at":"2014-10-17 15:35:10","updated_at":"2014-10-17 15:35:10","client_id":"0","enterprise_id":"0","usertype_id":"0"},{"id":"2","firstname":"","lastname":"","username":"seconduser","created_at":"2014-10-17 15:35:10","updated_at":"2014-10-17 15:35:10","client_id":"0","enterprise_id":"0","usertype_id":"0"}]}
URL입니다 심지어 브라우저 (I 인증을 위해 팝업을 얻고 그 후에 내가 브라우저에서 동일한 입력을받을)에서 작동합니다. 그래서 그것은 단지 guzzle을 통해 실패합니다.
지금 내 고객에 내가 설치 목구멍하고 나는이 노력하고있어 :$client = new GuzzleHttp\Client();
$user='[email protected]';
$pass='password';
$res = $client->get('http://myapi.api/api/v1/users', array(
'auth' => array('[email protected]', 'password')
));
$users=$res->json();
$users=$users['users'];
을 그리고 오류 얻을 :
[curl] (#18) See http://curl.haxx.se/libcurl/c/libcurl-errors.html for an explanation of cURL errors [url] http://myapi.api/api/v1/users
내가 잘못하고있는 중이 야 무엇을?
편집 : 명령에 -v 사용하여 내가 얻을 :
$ curl -v --user [email protected]:password http://myapi.api/api/v1/users
* Hostname was NOT found in DNS cache
* Trying 127.0.0.1...
* Connected to myapi.api (127.0.0.1) port 80 (#0)
* Server auth using Basic with user '[email protected]'
> GET /api/v1/users HTTP/1.1
> Authorization: Basic YWRtaW5AYWRtaW4uY29tOnBhc3N3b3Jk
> User-Agent: curl/7.37.1
> Host: myapi.api
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Mon, 20 Oct 2014 13:08:56 GMT
* Server Apache/2.2.29 (Unix) mod_fastcgi/2.4.6 mod_wsgi/3.4 Python/2.7.8 PHP/5.5.17 mod_ssl/2.2.29 OpenSSL/0.9.8za DAV/2 mod_perl/2.0.8 Perl/v5.20.0 is not blacklisted
< Server: Apache/2.2.29 (Unix) mod_fastcgi/2.4.6 mod_wsgi/3.4 Python/2.7.8 PHP/5.5.17 mod_ssl/2.2.29 OpenSSL/0.9.8za DAV/2 mod_perl/2.0.8 Perl/v5.20.0
< X-Powered-By: PHP/5.5.17
< Cache-Control: no-cache
< Set-Cookie: laravel_session=eyJpdiI6IjRPMk9TT0ZnZklTMG1uWlFDancyMWc9PSIsInZhbHVlIjoic1V1RjA5aVBJdFNLM0JLclNROEE1a0dCeHNEMWhVNFVReTlUOHdidE44WEJzRnB4WFkxdWo0V0ozcXFVSW9LYzZiZzZSSlFCNXNTTjl2Mzh4TlFtTUE9PSIsIm1hYyI6IjhlYzY0YjFkNTQzNjk5ZGMxNDk3YmY4ZjU4YTYzYzM4YzgxZjg1MzlhMWUxNWVjYWE4ZThlMmU0N2RjNWFkZGMifQ%3D%3D; expires=Mon, 20-Oct-2014 15:08:57 GMT; Max-Age=7200; path=/; httponly
< Transfer-Encoding: chunked
< Content-Type: application/json
<
* Connection #0 to host myapi.api left intact
{"error":false,"users":[{"id":"1","firstname":"","lastname":"","username":"[email protected]","created_at":"2014-10-17 15:35:10","updated_at":"2014-10-17 15:35:10","client_id":"0","enterprise_id":"0","usertype_id":"0"},{"id":"2","firstname":"","lastname":"","username":"seconduser","created_at":"2014-10-17 15:35:10","updated_at":"2014-10-17 15:35:10","client_id":"0","enterprise_id":"0","usertype_id":"0"}
편집 :이 질문은 내가 해결책을 발견하지 않았습니다이 프로젝트 때문에와 다른 길을 갔다하더라도 아마 너무 구체적이고 사양이 변경되었습니다. 누군가를 도울 수 있도록 여기에 남겨 둘 것입니다.
앤드리 다니엘 (André Daniel)이 논평에서 인증이 무언가를 깨고 나에게 내 원래 json을 제공하지 않아서 오류가 발생한다고 생각합니다.
http://myapi.api/api/v1/users/1
하지만 그래서 당신은 호출을 시도하는 경로가 확실
http://myapi.api/api/v1/users
을 목구멍을 통해이 URL을 호출 : 귀하의 질문에
오류 # 18은 * CURLE_PARTIAL_FILE을 의미합니다. 파일 전송이 예상보다 짧거나 길었습니다. 이것은 서버가 예상 된 전송 크기를 처음보고하고 이전에 제공된 크기 *와 일치하지 않는 데이터를 전달할 때 발생합니다. –
내 질문에 Andre가 업데이트되었습니다. 어떻게 해결할 수 있습니까? 나는 컬 (curl)을 많이 사용하지는 않았지만이 코드는 매우 비슷한 프로젝트에서 작업했습니다. –
해당 정보로 다시 편집 –