简体   繁体   English

PHP CURL将POST发送到Django应用问题

[英]PHP CURL sending POST to Django app issue

This code in PHP sends a HTTP POST to a Django app using CURL lib. PHP中的此代码使用CURL lib将HTTP POST发送到Django应用。

I need that this code sends POST but redirect to the page in the same submit. 我需要此代码发送POST,但重定向到同一提交中的页面。 Like a simple form does. 就像一个简单的表格一样。

The PHP Code: PHP代码:

$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. 在这种情况下,PHP正在发送HTTP POST,但未重定向到页面。 He is printing the result. 他正在打印结果。 My URL still .php and not a django/url/ 我的网址仍然是.php,而不是django / url /

I need be redirected to the django URL with the Post like a simple form in HTML does. 我需要使用Post重定向到django URL,就像HTML中的简单表单一样。

Any Idea? 任何想法?

Thanks. 谢谢。

Your code does a server-side POST request to the page. 您的代码会对页面执行服务器端POST请求。 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. 如果您需要一步完成操作,请打印出带有method =“ POST”和隐藏字段的表单,然后添加自动提交表单的JavaScript。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM