English 中文(简体)
cURL 设置空值( Flash as3)
原标题:cURL posts empty values (via Flash as3)

所以,我是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.

我知道它正确调用另一个文件, 因为它实际上在数据库中创建了一个条目, 但一切都是空白的。 每个字段。 我也知道另一个文件有效, 因为当我测试闪光文件离线时, 它有效, 而在网络上它不起作用 。

任何帮助都是有价值的。

最佳回答

不要创建您自己的查询字符串。 CURL 可以接受 PHP 阵列, 并为您做所有工作 :

$fields = array( foo  =>  bar ,  baz  =>  fiz );
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields);

Curl 不够聪明, 无法意识到您已经将字符串编码为 URL 格式, 所以它只是看到一个简单的字符串被张贴, 没有名称值 。

而且,

curl_setopt($ch,CURLOPT_POST,count($fields));

这不是你如何使用它。 CURLOPT_ POST 是一个简单的布尔值, 表示 PST 正在完成中。 如果您没有字段, 那么突然POST 是假的, 您正在使用其他方法, 比如, Get, 您的客户端应用程序无法期待的 Get 。

问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签