CakePHP sending POST data - cakephp

Inside my CakePHP 2.4 application I need to send POST headers inside my response.
It seems like Cakeresponse can send headers with the response:
http://book.cakephp.org/2.0/en/controllers/request-response.html#cakeresponse
Is there a similar way to put POST data inside response ?

Sending POST data without a form is mentioned here:
Sending POST data without form
and here
POST without Form Method (PHP)
But an AJAX solution is not suitable for me. I solved problem with sending data with headers. I created my own headers, added them to current headers and send data.

Related

AXIOS post request - missing url param

I set a react webpage that has is structured as follow:
MAIN PAGE www.localhost:3000.com,
OTHER PAGES www.localhost:3000.com/services, www.localhost:3000.com/about, www.localhost:3000.com/contactMe.
I'm using axios from www.localhost:3000.com/contactMe to perform a post for a contact form that will send data thru my backend/nodemailer.
Using Postman to verify the post status, the post method is NOT working from www.localhost:3000.com/contactMe/api/contact and it works correctly for localhost:3000/api/contact and localhost:5000/api/contact.
How could I fix this Request failed with status code 404 from www.localhost:3000.com/contactMe/api/contact?
HOST: localhost:3000
SERVER: app.use('/api,...)
CONTROLLER: pouter.post('/contact',...)
One solution could be to just use the base URL and send the POST request to www.localhost:3000.com/api/contact from any page.
So even if the user is on www.localhost:3000.com/contactMe, it still sends the request to www.localhost:3000.com/api/contact.
A quick way to get it is using window.location.hostname.
Another way is just putting a / in the beginning of the URL you're putting in your POST request axios.post('/api/contact', ...) and it should send it directly to ${baseURL}/api/contact from any page

How can I send a file along the headers of a POST call, while having regular data in the request body

I had an existing POST API which was used to sent an object to server. Now I want to attach a file to the header of the same file. Is it possible to do such a thing. Can a request have multiple content-type.
I tried using ngFileUpload directive, and provide my object to data field of Upload.upload method. However, by doing this the entire data object seems to go in header and the request fails.
Any suggestions for sending file in headers and JSON in request body of a POST call??
I eventually found out that a HTTP request can have a single Content-type. This is as per the standards. However it is still possible and quite easy to send data along with a file using the FormData Object. The support for FormData though is not across all the versions of various browsers.

"No Access Control Allow Origin" in AngularJS

I am trying to develop a website that reads a JSON response from a certain endpoint and post it after certain processing to the page.
I am using $http.get(url) (AngularJS)
However I am facing problems getting the response.
I have tried to use other URLs and it worked then the cause of the problem probably is not the code.
The Error is: "No Access Control Allow Origin header is present on the requested resource".
Other responses suggested something related to CORS and privacy issues ; but when i type the URL directly in my browser it gives a JSON response directly. (So basically there is no privacy issues in the server side right?)
My question is what should I do ? Is there another way to get the content of the page pointed by the url (i am sure that it will only contains the JSON response)
Thanks in Advance
I came across this question:
1. If we substitute the URL in the address bar, it is similar to receiving data from the server of this site
In order to send requests to other servers need to use JSONP HTTPS for secure channel
Sending data can be carried out, but with the replies received will be a problem in the form JSON
Please send to the server if use PHP, then use CURL
JS->Our server->Server api->Our server->JS

Get request to Json does it need jsonp

I am using Angular v1.2.15 to GET a URL to retrieve JSON results.
I need to send a custom AUTHENTICATION Header with the request.
the url will send back Json.
So far I can only get both $resource and $http to even send the request
if I use JSONP type of request. However when I do this it does not send
my CUSTOM HEADER. Can I retrieve JSON content using a normal GET request?
The problem was the Ripple Emulator for Cordova apps was running the proxy on a different port. The the emulator was actually not allowing the http request.

How to send a multipart/mixed HTTP POST request through Runscope?

I want to send a HTTP POST request with Content-Type: Multipart/mixed using Runscope.
Any help/guidance would be great.
There are a couple ways to send data through us, each with varying support for multi-part form data.
Dashboard
When making requests through the dashboard, there is currently no way to add files or other multi-part data to a request. This is something we plan to support in the future, but we don't have a specific timline for implementing it yet.
From your code, via a Runscope URL
When you make a request from code that includes multipart data, it will be relayed through the Runscope URL in tact. The dashboard will display the file meta data that it relayed, but the files are not stored or displayed and retries will not re-send the file data again.
We're happy to help answer any questions in more detail by emailing us at help#runscope.com any time.

Resources