所以,我是 cURL 的菜鸟,但由于我在使用 php 通过 flash as3 将数据插入数据库时遇到了一些问题(文件位于不同的服务器中),因此建议我使用 cURL 脚本来桥接它们.
所以这是我的 cURL 代码(这是从另一个问题复制粘贴的,我只是更改了值,如果这里有任何明显的错误,请见谅):
<?php
//where are we posting to?
$url = 'url'; //I have the correct url of the file (insert.php) on the other server
//what post fields?
$fields = array(
'Nome'=>$_POST['nome'],
'Email'=>$_POST['email'],
'Idade'=>$_POST['idade'],
'Profissao'=>$_POST['profissao'],
'Pais'=>$_POST['pais']
);
//build the urlencoded data
$postvars='';
$sep='';
foreach($fields as $key=>$value)
{
$postvars.= $sep.urlencode($key).'='.urlencode($value);
$sep='&';
}
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$postvars);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
?>
这是闪存 as3
function WriteDatabase():void{
var request:URLRequest = new URLRequest ("curl.php file here");
request.method = URLRequestMethod.POST;
var variables:URLVariables = new URLVariables();
variables.nome = ContactForm.nomefield.text;
variables.email = ContactForm.emailfield.text;
variables.idade = ContactForm.idadefield.text;
variables.profissao = ContactForm.proffield.text;
variables.pais = LanguageField.selectedbutton.text;
request.data = variables;
var loader:URLLoader = new URLLoader (request);
loader.addEventListener(Event.COMPLETE, onComplete);
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.load(request);
function onComplete(event):void{
trace("Completed");
}
}
// I am assuming (incorrectly perhaps) that if is called the same way you would call a php file. It also traces "Completed" inside the flash, so it comunicates with it.
我知道它正确地调用了另一个文件,因为它实际上在数据库中创建了一个条目,但一切都是空白的。每个领域。我也知道另一个文件可以工作,因为当我离线测试闪存文件时它可以工作,只是在它在线时不行。
任何帮助都将不胜感激。