所以,我是CURL中一个彻头彻尾的人物, 但是由于我使用php 将数据插入数据库时遇到了一些问题, 我建议我使用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.
我知道它正确调用另一个文件, 因为它实际上在数据库中创建了一个条目, 但一切都是空白的。 每个字段。 我也知道另一个文件有效, 因为当我测试闪光文件离线时, 它有效, 而在网络上它不起作用 。
任何帮助都是有价值的。