嗨,我在POST请求中尝试PHP Post Request,认为它可能对我有用,我的代码如下所示
$sub_req_url = "http://localhost/index1.php";
$ch = curl_init($sub_req_url);
$encoded = '';
// include GET as well as POST variables; your needs may vary.
foreach($_GET as $name => $value) {
$encoded .= urlencode($name).'='.urlencode($value).'&';
}
foreach($_POST as $name => $value) {
$encoded .= urlencode($name).'='.urlencode($value).'&';
}
// chop off last ampersand
$encoded = substr($encoded, 0, strlen($encoded)-1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $encoded);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_exec($ch);
curl_close($ch);
Run Code Online (Sandbox Code Playgroud)
形成index.php文件和index2.php是同一目录中的另一个文件,当我打开页面时,我的error.log文件中出现以下错误
[Sat Dec 18 15:24:53 2010] [error] [client ::1] PHP Fatal error: Call to undefined function curl_init() in /var/www/testing1/index.php on line 5
Run Code Online (Sandbox Code Playgroud)
我想要做的是我有一个发送帖子请求的预订表格,然后我想处理帖子值并再次发送请求到paypal
Rus*_*lex 125
您需要为php安装CURL支持.
在Ubuntu中,您可以通过它安装它
sudo apt-get install php5-curl
Run Code Online (Sandbox Code Playgroud)
如果您正在使用apt-get,那么您将不需要编辑任何PHP配置,但您需要重新启动Apache.
sudo /etc/init.d/apache2 restart
Run Code Online (Sandbox Code Playgroud)
如果您仍然遇到问题,请尝试使用phpinfo()以确保将CURL列为已安装.(如果不是,那么您可能需要打开另一个问题,询问为什么您的软件包没有安装.)
PHP CURL文档中有一个安装手册.
小智 23
对于Windows,如果有人感兴趣,请从php.ini取消注释以下行(通过删除;)
;extension=php_curl.dll
Run Code Online (Sandbox Code Playgroud)
重启apache服务器.
对于Ubuntu:extension=php_curl.so如果需要,添加到php.ini以启用.然后sudo service apache2 restart
这通常是自动处理的,但有些情况 - 例如,在共享开发环境中 - 可能需要手动重新启用.
指纹将匹配所有这三个条件:
我通过以下步骤在ubuntu 16.04中工作.我的php版本是7.0
sudo apt-get install php7.0-curl
sudo service apache2 restart