Curl to localhost return not found
punk73 opened this issue · comments
I tried this
$url = 'localhost/fa_quality/public/api/qualities';
$response = Curl::to($url)
->enableDebug('./logFile.txt')
->get();
return $response;`
but it's always return like below :
and here is the log file :
* Hostname 136.198.117.21 was found in DNS cache
* Trying 136.198.117.21...
* Connected to 136.198.117.21 (136.198.117.21) port 8080 (#0)
> GET HTTP://localhost/fa_quality/public/api/qualities HTTP/1.1
Host: localhost
Accept: /
Proxy-Connection: Keep-Alive
* HTTP 1.0, assume close after body
< HTTP/1.0 404 Not Found
< Date: Tue, 20 Feb 2018 05:21:33 GMT
< Server: Apache/2.2.15 (CentOS)
< Content-Length: 304
< Content-Type: text/html; charset=iso-8859-1
< X-Cache: MISS from localhost
< X-Cache-Lookup: MISS from localhost:8080
< Via: 1.0 localhost (squid/3.1.10)
* HTTP/1.0 connection set to keep alive!
< Connection: keep-alive
<
* Connection #0 to host 136.198.117.21 left intact
I try my end point with postman, it work fine.
I try another end point such as https://jsonplaceholder.typicode.com/posts
with withProxy
method and it work fine.
what should I do ? am I missing something ?
well, found the problem. I need to set 'localhost' or 127.0.0.1 as my proxy and 80 as my port. so, php can access my localhost using that proxy. not the proxy that I use for my computer.
$url = 'localhost/fa_quality/public/api/qualities';
$response = Curl::to($url)
->enableDebug('./logFile.txt')
->withProxy('127.0.0.1', 80 ) //localhost port
->get();
return $response;
it fix my problem.
Glad it all worked out.