I'm trying to write a Flask application that incorporates a PHP script via a POST request using the requests module. I've had success on my local machine where I post
requests.post("http://localhost/webapp/templates/script.php", data=blah)
and everything goes as expected. However, when I push my code to Heroku, the post request no longer works - instead, I'm redirected to
http://mysite/php_post
and get a
Internal Server Error
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
I guess you want to be posting the data to your heroku application
requests.post("http://localhost/webapp/templates/script.php", data=blah)
should be
requests.post("http://mysite/webapp/templates/script.php", data=blah)
Related
does this API just not work via cross origin resource? My CORS headers are set in .htaccess and verified working, because I do get a response from the API, but it's an unknown error.
I set everything up and tested on a single test server and it all works. But my prod environment requires two separate domains, one which is a CMS where the pages are hosted, and then a separate PHP server where I'm hosting the PHP side of the app that makes the CURL requests. When I try to make a CORS request, I get
{"error":{"code":500000,"message":"An unexpected error occurred. If the error persists, report it with date/time of error, request identifier from response header X-RequestId, and client identifier from request header X-ClientTraceId."}}
I get the same thing when I mimic a CORS scenario locally by using a XAMPP PHP server and a Gulp HTTP server.
My setup currently builds the JSON from body copy on a page, then sends that via AJAX POST to the PHP file, which then processes it, encodes, makes Curl requests to the API, then outputs the response. I then handle the data from the response again in the JS file.
I am developing an application in IONIC. I am making a $http.get request in Angular JS and its giving me 404 error when I successfully login and trying to load the user profile using the token sent in the authentication header.
It produces error in chrome, although I enabled CORS. Please check the screenshot:
Now if I try the url in POSTMAN, everything is ok. See the screenshot below:
I am stuck with this error, can someone help me?
What Ionic says
There are two ways to solve the issue: The first, and easier, solution is to just allow all origins from your API endpoint. However, we can’t always control the endpoint we are accessing. What we need, then, is a request that does not specify an origin.
We can do this by using a proxy server. Let’s look how the Ionic CLI provides
Reference
What works but isn't completely good to use
A simple solution is just add a CORS plugin into your browser and everything will work.
Plugin Link
Proxy server
If you want a proxy server there is this tutorial:
Link
I have a website that is using jQuery's $.post method to submit a contact form to a PHP script that processes the info and sends it via email. I have tested the script locally and it's working properly. When I try to run it on the server, the ajax request to the processing script sits as (pending) for ~3 minutes before returning a status of 404. However if I inspect the request and navigate directly to the Request URL I can see that the script is indeed there and functioning properly.
The most bizarre thing, though, is that it returns an nginx 404 error. The server is running Apache, not nginx. Also, the site has a custom 404 page that works properly if you navigate to any non-existent page.
As a first test, I created another PHP script that simply echoes a string, put it in the same location as the form processing script, and AJAX requests to that work just fine. It's only the request to the processing script that doesn't go through.
You can view the page here with the contact form and AJAX Test. http://dev.alpha1marketing.com/contact/ When you submit the contact form a loader will spin indefinitely and if you inspect the request you'll see it pending for a few minutes before returning the mysterious 404. The Ajax Test button returns the request almost immediately.
Here is the code that posts the form submission to the form processing (this doesn't work)
# Post the form
$.post('/wp-content/themes/alpha1/ajax/send-contact.php', {
firstName: $.trim($('#firstName').val()),
lastName: $.trim($('#lastName').val()),
email: $.trim($('#emailAdress').val()),
referral: $.trim($('#referral').val()),
comment: $.trim($('#comment').val())
},
(response)->
# Show some messages
return
)
And here is the code that posts to the "test" script (this does work)
$.post('/wp-content/themes/alpha1/ajax/test.php', {
}, (response)->
console.log response
return
)
I'm fairly certain this has something to do with the server/network configuration, but I'm stumped as to what aspect of it. There's another site being developed in parallel you can view at http://dev.krasdalefoods.com/contact/, and it's having the same issue using the same form processing code.
The two dev. domains are hosted on Bluehost, and the plan is for the primary domains to move over to Bluehost once the sites are complete. The client purchased and initially configured some aspects of the server before giving me access to the control panel to set up what I needed so it's possible that something they did is causing this issue, but I'm not sure what it could be. I believe the primary www.alpha1marketing.com and www.krasdalefoods.com domains are hosted on IIS, so that couldn't be causing the nginx error either.
Any help debugging this would be appreciated!
Turns out that the issue with nginx was a red herring. The problem was the fact that BlueHost doesn't allow you to send messages through an external SMTP server - only through theirs. I was trying to send the messages through Gmail and that request was being blocked by BlueHost, which was causing their nginx middleware to see nothing but a hung script and return a 404.
Switching my mailer script to use PHP mail() was, unfortunately, the way I had to go. It still works!
I've got an app engine app set up. It's set up with billing and I have extension="curl.so" in my php.ini file so I think cUrl should work. It is set up to allow cross domain requests.
I'm attempting to send data (via a jquery ajax post) to the app, then have it use curl to send the data somewhere else.
If I send no data with the ajax request, the curl works and the final destination responds telling app engine that there's no data, app engine successfully passes it back to the ajax callback (as expected).
However if I send data along, the app engine responds with a 500 error. It appears to be breaking during the curl_exec.
Everything works fine if I run it through the local server.
Does anyone have any idea what might be inhibiting app engine from allowing this?
I am developing an iPhone application that sends through HTTP requests an XML file to my PHP server.
I have coded my server and got the XML file and stored it in database. Now I want to see from my iPhone if the server got my XML file.
This response of the server, I must code it or is it automatic?
If it is not automatic, how do I make it? I must make the server send back a simple XML to my iPhone stating that everything is "OK" and also program my iPhone application to get the XML?
Assuming you have set up some proper API for your App to query, just use HTTP Status Codes. If everything was ok and the data got successfully inserted, reply with a 200 response. If there was an error there are numerous other status codes to send, e.g. 500 internal server error. Your client App can then parse these responses and react appropietly.