Angular $http PUT requests return status -1 - php

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:

Related

Local Angular's proxy to local api can't connect

I'm having trouble getting my local dev server of an Angular app to connect to my local PHP server of my api.
It's pretty much exactly the same problem expressed in this question:
ECONNREFUSED for proxy request from localhost to another localhost
Imagine the following:
/api (PHP API source)
/myapp (angular app)
I run the following in /api:
php -S localhost:8000
Then, in /myapp, I run the following:
ng serve
In my app, I have the following proxy.conf.json:
{
"/api.php/v1/User": {
"target": "http://localhost:8000",
"secure": false,
"logLevel": "debug",
"changeOrigin": true
}
}
/api/api.php is the main entrypoint for all api calls. I then use the rest of the address to identify the correct call, prepended by /v1/User.
I've confirmed that the API runs fine by it's self. But when accessing the app in the browser the following errors occur:
[HPM] POST /api.php/v1/User/Auth -> http://localhost:8000
[HPM] Error occurred while trying to proxy request /api.php/v1/User/Auth from localhost:4200 to http://localhost:8000 (ECONNREFUSED) (https://nodejs.org/api/errors.html#errors_common_system_errors)
No errors are received on the PHP server side, which leads me to believe the proxy isn't even talking to the PHP server.

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?

Post request missing payload

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.

Catching requests made in xampp with fiddler

I have a simple php file which makes SOAP requests. This is running on my local computer with XAMPP as a webserver.
I am trying to catch the request made in fiddler, I can see the request to my php file but that just returns the html for the page. I want to catch the request made when I create the SOAP client to see what is being sent off.
Is there some setting in fiddler I need to change to be able to see the response? Or some sort of proxy I can send my request through so it is visible in fiddler?
You can pass the proxy settings to the SoapClient class like this:
$client = new SoapClient("request.wsdl", array('proxy_host' => "localhost",
'proxy_port' => 8888));
This assumes that fiddler is running on it's default port (8888).

xcode Unsupported URL when sending request

I am trying to send a GET Http Request to my computer that runs an Apache server.
When I send the request from XCODE to X.X.X.X\my_script.php using sendSynchronousRequest I get a response - Unsupported URL.
However, if I try to connect to this address using my browser it works fine.
Any suggestions? does it not support an address which contains IP?
Change slash in your request: X.X.X.X/my_script.php

Categories