Catching requests made in xampp with fiddler - php

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).

Related

Getting the clients Cookies from a PHP Ratchet WebSocket Server

I have a PHP Ratchet WebSocket server, running a custom chatroom on my website.
I would like to get the user's cookies when they connect to the server, so that I can get their session data and do something special if they are logged in / have specific permissions / etc.
In other posts (both on StackOverflow and otherwise), it is said that to get session data, you must get the client's cookies, which are supplied in their requests to the web server. The following line of code is meant to do this:
$conn->WebSocket->request->getCookies()
Where $conn is a ConnectionInterface.
My problem is, that when run this simply returns an empty array, even though the DevTools will show that there are indeed cookies.
Why might this not be returning a value?
just in case you're still searching for a solution:
1.In case your cookies only valid for a specific domain/subdomain - you should establish connection to your WebSocket server over the same address.
For example, cookies that only valid for admin.example.com won't be sent to a WebSocket server on your root domain (example.com).
2.In case your cookies only valid for a secure connection (https://), your WebSocket server should be over a secure connection too (wss://), Which is quite easy to achieve with the latest Ratchet version.
$webSock = new React\Socket\Server('0.0.0.0:8443', $loop);
$webSock = new React\Socket\SecureServer($webSock, $loop, [
'local_cert' => 'path_to_server_cert',
'local_pk' => 'path_to_private_key',
//'allow_self_signed' => TRUE,
'verify_peer' => FALSE
]);
3.With Ratchet 0.4.x, there is no longer a cookie parser.
You can only get it as a raw string and then parse it by yourself.
Get & Parse cookies with Ratchet 0.4.x :
$cookiesRaw = $conn->httpRequest->getHeader('Cookie');
if(count($cookiesRaw)) {
$cookiesArr = \GuzzleHttp\Psr7\parse_header($cookiesRaw)[0]; // Array of cookies
}

download ISP is different to request ISP

I am trying to download an external file using guzzle. This is the code that I use:
$url = 'https://testurl.net/dl/test.mp4?mime=true';
$path = storage_path('app/remote-uploads/test.mp4');
$client = new Client();
$client->get($url, ['sink' => $path]);
The code works and downloads from localhost just fine but when I push it to production I receive this error:
Client error: `GET https://testurl.net/dl/test.mp4?mime=true` resulted in a `403 Forbidden` response:
{"status":403,"msg":"download ISP is different to request ISP. request: AS20115 download: AS30083"}
I am not quite sure how to go about this and would really appreciate any help!
Seems that you are using https://openload.co/api#download-getlink to get a download link and download it then.
In this this I can assume that you hosting provider uses different IP for each outgoing HTTP request, and these IPs are even from different ASs (you think about them as "namespaces", check AS20115 and AS30083). And this particular site (openload.co) treats the situation like a security problem and prevents downloading (the second request).
There is nothing you can do on the application level. You have to talk to you ISP about it's routing rules. Maybe ask about (buy) a static IP address.
You can try to play around HTTP 1.1 keep-alive connections to send all requests through the same connection, but it depends on a server, and openload.co might not support this feature.
P.S. Please, include more details in questions in the future. Others are not wizards to read context from your mind :)
if you using vpn. please disable it

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.

Soap client stopped working

I have a website which frequently makes SOAP calls to a particular API. The site was working fine for a few months of time, however the SOAP functionality suddenly stopped working without any known reason, the error was "Cannot connect to host".
The WSDL service has not moved or shut down.
After this I updated plesk from version 12 to version 17. SOAP client is still not working but now its a different error:
SOAP-ERROR: Parsing WSDL: Couldn't load from (URL) : failed to load external entity (URL)
This is my SOAP call:
$opts = array('http'=>array('user_agent' => 'PHPSoapClient'));
$context = stream_context_create($opts);
libxml_disable_entity_loader(false);
$client = new SoapClient($url,array('stream_context' => $context,'cache_wsdl' => WSDL_CACHE_NONE));
Any possible solutions?
EDIT:
New information came in, so the API server had DNS problems, how can I restore my connection to the API?
Your php server is clearly not reaching out the soap server. This might help:
Try checking directly from php server if the service are reachable:
wget {url} > page.txt
nano (or equivalent) page.txt
Try using other program to consume the server, I suggest Soap Ui
On the php server try ping the service url and see if the IP is resolved.
Check if any other soap service is reachable, you can use this service
If this not help you coming up with a solution, post here the results to help others solving it.

Ratchet: How to connect via PHP to it?

I am running a Ratchet Server
$app = new Ratchet\App( 'localhost', 8080 );
$app->route( '/api', new API );
$app->run();
It is very easy to connect via JavaScript (and send some messages to the server):
_connection = new WebSocket( "ws://localhost:8080" );
Now I want the same from PHP (connect and send messages), but I dont know how and I dont find any information in the documentation of Ratchet.
Is it somehow possible? I really need to send messages from PHP to the clients (JavaScript), when there is some event on the server.
Edit: I really just need to "fire&forget" some simple message. Nothing fancy.
It works a bit wrong.
After connecting to the server, you can send a message from the client to the server and from the server to the client.
In the Connection Interface is the "send" method.
And call onSubscribe or onPublish method you have $topic variable.
In the $topic is the "broadcasting" method.
You need call:
$conn->send($message); or $topic->brodcasting($message);
If you need send client message after action on site, use example on ratchet (we need install ZMQ)
It works like this:
You create server. This server recieve message from users and recieve message from ZMQ.
Your site publish on ZMQ message
Your server receive message from ZMQ and broadcasting on users
Regards Maxim

Categories