Post request missing payload - php

I'm building an api that receives incoming webhooks from external parties. Post requests to my application lack a body in some cases. In my logs I see the incoming request with the following header:
Accept: */*
Content-Length:
Content-Type: application/json
As you can see the content-length is empty.
I cannot reproduce the problem. What I've tried thus far:
The request payload is only missing coming from a specific third party. If however, I provide this third party with a different callback url like request bin, the payload is not missing.
Connected this party source to our test environment. Which has exactly the same configuration (checked the entire php.ini) and the same version of our software. On our test server, requests are received with payload.
When sending post requests with Postman to our production environment, webhooks are received with payload.
Both test and production are https. I've tried sending http requests to our production server to see what happens, and I get an error as expected and no received headers in our logs.
Checked the php post_max_size, which is on 24M.
When creating a callback.php file in my public folder, and have the third party send it's webhooks to this destination, I am able to write the results to a log with the following code, which includes a payload. If I to output php://input later on in my Laravel application, it doesn't work:
$postdata = file_get_contents("php://input");
$file = fopen("webhook.log","w");
echo fwrite($file,$postdata);
fclose($file);
Both servers are running on the same php version (php7), and I am at a loss as to what to try next.

Found it! The problem was a port 80 to 443 redirect in a vhost configuration. I earlier dismissed redirects - which seem to be a common source of missing payloads in post requests - as possible cause; I had made a test script which succesfully received payloads on this very same server.
However, I had placed this test script in the servers public folder, which was not subject to the same redirects as was the root of my application. After removing the redirect, payloads where received as expected.

Related

Headers sent in curl request from php are working on one server and not on another

I have a weird problem, sending curl request with headers from one server abc.com to another server xyz.com are working while they are not working with another server xyz1.com and its not a subdomain.
I am getting 400 bad request error from xyz1.com server.
Can you help me to get clue what needs to be added to curl request code or need to change in server settings?

How to send a manual POST request of which I have a file with data?

we're using a custom built cart system and during high loads our payment system (Worldpay) times out.
When this happen we receive an email containing the POST request that failed, and this is a .txt file done like the following:
POST /index.php?xxx=yyy&zzz=xxx HTTP/1.0
Content-Length: 917
Host: ourdomain.com
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
User-Agent: WJHRO/1.0 (WorldPay Java HTTP Request Object)
parameter1=value&parameter2=value2
How can I actually quickly resend this request to my server so it can register the payment now that the load is more normal? I have this in a .txt file, is there a quick way to do it using this file as it is? Curl? Browsers? In a way so I can see the response to check that all is ok.
Thanks so much!
Depending on the needs you have exposed, it is likely that tools such as POSTMAN could help you, allow you to send http requests through an intuitive interface, you can use the various parameters, that are sent to you in the file you mentioned and run the same request check for any errors.

Angular $http PUT requests return status -1

I have a PHP REST API running on Apache2 Webserver inside an Ubuntu machine.
I'm trying to send PUT requests to my server with no success.
When I'm sending the request inside my localhost (same origin) - it works.
When I'm sending the request on my Docker containers (same origin) - it works.
When I'm sending the request from my Angular client to the server in development environment (cross-origin) - I received a weird status -1 error in the return of the request.
From sending the request from PostMan Chrome Extension - it works perfectly, but I see nothing special in its request headers.
This is my code for sending the request:
return $http.put(path, params).then(successCallback, errorCallback);
This is a picture of the returned status:

Ajax Request Rejected

I am trying to upload a file using an (jquery) AJAX request but it fails and the response sent is
Request Rejected
The requested URL was rejected. Please consult with your administrator.
Your support ID is: xxxxxxxxxxxxxxx and provide steps to replicate the issue
I've tried to visit the URL using browser and that works fine.
Is there anything related with the AJAX request or is it entirely a server side issue? How can I solve this?
Your message is being generated by a Big IP ASM
When an Illegal HTTP status violation occurs, the BIG-IP ASM sends an HTTP blocking response page that includes the OWS Server header.
So the problem is not on your side, it's on the web server side.
When origin in request header is null, server doesn't allow request. read about CORS at http://en.wikipedia.org/wiki/Cross-origin_resource_sharing Cross Domain request can be allowed from php server as
header("Access-Control-Allow-Origin:*");
and enable all methods for request.
header("Access-Control-Allow-Methods: POST, GET, OPTIONS");

How to send and recieve responses from one server to another server

I want to send an ajax request to a server where my db connections and other things works. What I want is to send 2 post values through ajax to that server and that server will give a response back. See example code below.
post_data = {'userName':name, 'userPass':password};
$.post('http://www.example2.com/script.php', post_data, function(response){
//doing something with response
}
This code is in example1.com and we are sending post data to example2.com. But when I try this I get an error that is given below.
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://www.example2.com/script.php. This can be fixed by moving the resource to the same domain or enabling CORS
So I have to enable something. I have no idea how to enable CORS. How to do that?

Categories