This code in PHP sends a HTTP POST to a Django app using CURL lib.
I need that this code sends POST but redirect to the page in the same submit. Like a simple form does.
The PHP Code:
$c = curl_init();
curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($c, CURLOPT_URL, "http://www.xxx.com");
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, 'Var='.$var);
curl_exec($c);
curl_close ($c);
In this case, the PHP is sending the HTTP POST, but is not redirecting to the page. He is printing the result. My URL still .php and not a django/url/
I need be redirected to the django URL with the Post like a simple form in HTML does.
Any Idea?
Thanks.
Your code does a server-side POST request to the page. You can't "redirect" the user to the same "instance" of the page.
If you need to do it in one step, print out a form with method="POST" and hidden fields and then add JavaScript which automatically submits it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.