sho
sho

Reputation: 761

Issue with Laravel Route and POST

I'm having an issue submitting post requests using Laravel. The following works locally using docker with Laravel 9.21.6 and PHP 8.1.0. When I try on the live server running NGINX with Laravel 9.21.6 and PHP 8.1.8, I get nothing. What am I missing?

Route::post('orders', function (Request $request) {
    return ($request);
});

If I try the following curl request:

curl -v -X POST -d "{'order':18}" "http://localhost/api/orders"

I get order printed:

Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying 127.0.0.1:80...
* Connected to localhost (127.0.0.1) port 80 (#0)
> POST /api/orders HTTP/1.1
> Host: localhost
> User-Agent: curl/7.79.1
> Accept: */*
> Content-Length: 12
> Content-Type: application/x-www-form-urlencoded
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Host: localhost
< Date: Sun, 31 Jul 2022 18:41:08 GMT
< Connection: close
< X-Powered-By: PHP/8.1.0
< Cache-Control: no-cache, private
< Date: Sun, 31 Jul 2022 18:41:08 GMT
< Content-Type: application/json
< X-RateLimit-Limit: 60
< X-RateLimit-Remaining: 59
< Access-Control-Allow-Origin: *
< 
* Closing connection 0
{"{'order':18}":null}% 

But if I try on the server:

curl -v -X POST -d "{'order':18}" "https://server.com/api/orders"

I get nothing:

Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying 54.145.34.166:443...
* Connected to api.wenusvi.com (54.145.34.166) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*  CAfile: /etc/ssl/cert.pem
*  CApath: none
* (304) (OUT), TLS handshake, Client hello (1):
* (304) (IN), TLS handshake, Server hello (2):
* (304) (IN), TLS handshake, Unknown (8):
* (304) (IN), TLS handshake, Certificate (11):
* (304) (IN), TLS handshake, CERT verify (15):
* (304) (IN), TLS handshake, Finished (20):
* (304) (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / AEAD-CHACHA20-POLY1305-SHA256
* ALPN, server accepted to use http/1.1
* Server certificate:
*  subject: CN=wenusvi.com
*  start date: Jun 18 19:22:18 2022 GMT
*  expire date: Sep 16 19:22:17 2022 GMT
*  subjectAltName: host "api.wenusvi.com" matched cert's "api.wenusvi.com"
*  issuer: C=US; O=Let's Encrypt; CN=R3
*  SSL certificate verify ok.
> POST /api/orders HTTP/1.1
> Host: api.wenusvi.com
> User-Agent: curl/7.79.1
> Accept: */*
> Connection: close
> Content-Length: 12
> Content-Type: application/x-www-form-urlencoded
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Server: nginx/1.18.0 (Ubuntu)
< Content-Type: text/html; charset=UTF-8
< Transfer-Encoding: chunked
< Connection: close
< Cache-Control: no-cache, private
< Date: Sun, 31 Jul 2022 18:40:55 GMT
< X-RateLimit-Limit: 60
< X-RateLimit-Remaining: 59
< Access-Control-Allow-Origin: *
< 
* Closing connection 0

Upvotes: 0

Views: 114

Answers (1)

sho
sho

Reputation: 761

After much trial and error, the issue had to do with php-fpm. It seems the server was caching the output. Initially, this URL did not output any results, so the server cached that "data" and any further calls returned the empty data. Restarting php-fpm worked so I did some more searching and came across an article that advised changing opcache to 0. See https://serverfault.com/questions/991843/why-does-php-fpm-sometimes-get-stuck-serving-old-files

Upvotes: 0

Related Questions