I have a ticketing system and I just enabled an API endpoint that points to a custom PHP file I created. Everytime I update a ticket it sends the data to this endpoint saying its updated. How do I test if it actually is sending any data? Supposedly its doing a POST to that php file. I was thinking of sending this POST data to a a plain text file in the same folder to test.
But is there a better way to do this to test what that end point is sending?
Did you try checking the network tab in chrome dev tools. There you can look up under "doc" or "XHR" which post headers have been sent.
You need to log your inputs, outputs, or anything you want. There is a good log library you can use that name is Monolog but you can use the buffer or write in output using var_dump or write directly in a log file.
Also, you can use the XDebug to debug your codes
Related
I have been struggling with this one quite a bit... Some background - my React front end is running on a LAMP back end (company's set up not my choice) and I currently have the task of creating a contact form that when submitted - will send the form data to a PHP script which should then trigger an email to be sent to a specific inbox we have set up.
I feel as though I understand the form portion correct as I am most comfortable with HTML/CSS/JS/React, but the LAMP stack set up is really throwing me. I'll try to list specific questions clearly below.
How would one directly target a file on an EC2 instance?
I am currently getting a 500 error (failed to load resource) from the server when attempting to target my PHP file. I have tried an absolute path from the root of the server as well as a path from the root directory of the project. Either way it fails.
I am getting a React warning in console "Form Submission failed because form is not connected", but to my knowledge the form is connected... The action attribute is tied to the PHP file that I would like to send data to.
Currently I have an async await call running when the form is submitted which is supposed to make a fetch/POST call to the file and then things should be handled, but again I am having the issues listed above.
I do not want to share publicly share code because this is a company project, but if someone has experience with this type of set up and has time to help someone trouble shoot please let me know. Sorry for the novel folks and thank you for any help!
Edit - is there any type of work around I could use to avoid even sending this to PHP script and generating an email an alternative way besides emailJS?
If you've created a standard html form then the presumably you have action and method attributes on the form.
You would traditionally:
Set the form action attribute to point at your php script. There should be no reason the php script isn't directly accessible unless it's off document root or you have a .htaccess file that is routing all requests through an intermediary (like an index.php file).
Set the form method attribute to POST.
The PHP script directed to in the action should read from $_POST which is an array that will contain any data sent via POST request to your php script.
You can then use a variety of methods for sending the email. Since you've mentioned EC2 you're obviously in AWS. In this case AWS offer a great email service called Simple Email Service. You can find the SDK and example scripts for sending an email via it here: https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-using-sdk-php.html
However, do note that SES requires you to go through a verification process as you will initially be in a sandbox mode that has certain restrictions.
I am trying to write code to download files from a financial data website. The file is accessible and easily downloadable by clicking the page, but my goal is to be able to reach the file via a POST request, with what I could deduce from Chrome's inspector.
My request never seems to reach the downloadable zip file, I'm not certain how it is wrong, I probably missed something reading the html.
This is the page
This is the request I'm sending through Postman (POST):
http://www.histdata.com/get.php?tk=216a804365eccace285d20afed7acefe&date=2000&datemonth=2000&platform=ASCII&timeframe=M1&fxpair=EURUSD
POST is not going to work on a get.php url.
use something like CURL to read the file from an external web.
I'm in the process of trying to better understand http, more specifically I want to get comfortable working with web based APIs. Some of the documentation I've read for specific API's mention that the API will expect to get an http request in exactly this format, with specific headers and content.
I'm trying to use php cURL, but googling around I haven't found a way (that I understand) simply print my http request to the screen or a text file rather than sending it. I want to make sure that the request I'm constructing looks how I intend it to, rather than just getting back a success or failure message from whatever server the request is sent to. Is there an easy way to do this?
You should try using Fiddler. Fiddler show RESPONSE and REQUEST HEADER. Other than that you can install some extension to your browser that shows HEADER, Firefox does have such extension I think it is called LiveHTTP... sorry didn't remember name.
For web debugging Fiddler is what you need http://fiddler2.com/
A webhook is sending me a POST, and I want to do some debugging on it. Currently I'm looping over the array and then sending a mail() to myself instead of printing (because how could I see what's printed to the page?), but I'm betting there's a more efficient way.
Any suggestions?
https://requestbin.com/ lets you create a temporary URL that will show you all the HTTP request data sent to it.
There are multiple options for debugging:
Use a debugger with an IDE, like netbeans. This will run the application and figure out where things are going wrong.
Use logfiles of your server, or generated by application exceptions
Collect your debug information with a buffer and put it in a file in your public directory. Overwrite with every new request.
I know this is quite an old question but if you want to see what kind of responses you are going to get from webhooks or you need to need to access the developer environment then there are a selection of tools that can help you.
RequestBin is probably one of the simplest to use by, providing a unique URL that you can then set this as your endpoint for Event notifications. Using this URL you can check to see what responses you are receiving.
You can generate a unique URL by creating a RequestBin.
An Example URL is this:
http://requestb.in/XXXXXXXX
This will be used to receive Event Notification Data and Receive Inbound Parse Data.
The results will then be found by heading to your RequestBin unique URL.
Ngork is also a tool that is useful for creating a local tunnel to your machine. This makes testing webhooks locally easy.
To setup install and enter the following in your CLI (after signing up first):
$ ngork 3000
This would open a connection to the port 3000 that is on your local machine, then at a URL you can put your URL for your PARSE Webhook or Event Webhook.
$ ngrok -subdomain=myappname 3000
Runscope is a tool for debugging APIs. It acts as a proxy, collecting all data sent to it and passes it on to another point. You may then, later, review what was sent to the API you’re debugging.
Source : https://sendgrid.com/docs/API_Reference/Webhooks/debug.html
http://httpresponder.com/ works also, and lets you configure a canned response if you need one.
You can use https://www.reliablewebhook.com/. They also have a plugin for Visual Studio Code for local debugging.
When you enter soap servers url in browser, normally it produces blank page. But if memory serves me I saw somewhere something like
Hello, this is our soap service. For
documentation please follow this link.
To get an account, please follow this
link. Blahblah.
How can I do that? (Using PHP SoapServer, if that matters).
I did try to just print everything at the bottom of soap-server-handling php code but in that case soap server doesnt work when called from proper soap client.
The example you saw doing that was probably checking for one or more things in the headers and acting upon what it saw. For example, it could inspect
USER_AGENT
ACCEPT
ACCEPT_ENCODING
etc, etc, etc.
For you to do this in PHP, you will need your check to be run before your SoapServer gets the request. You can access the header values by inspecting $SERVER. Most of them will start with HTTP. To get started just
print_r($_SERVER);
What you want to do is look into WSDL (Web Service Description Language). Languages like .NET produce them for you.