http://wap.lenovomobile.com/cp/log/import.do 我想往这个地址里post数据$params,$params可能比较大。

解决方案 »

  1.   

    $url="http://wap.lenovomobile.com/cp/log/import.do";
    $ch = curl_init($url);
    echo "ch==".$ch."<br>";
    curl_setopt($ch,CURLOPT_POST,1);
    curl_setopt($ch,CURLOPT_POSTFIELDS,$params);
    curl_setopt($ch,CURLOPT_URL,$url);
    $ret = curl_exec($ch);
    curl_close($ch);print_r($ret);
      

  2.   

    yueliangdao0608(骑上帝他媳妇儿打猎) : 还是不行啊。
      

  3.   

    ch==Resource id #2
    1这是我执行的结果。
    应该是你的 curl 环境 的问题。
      

  4.   

    手册上蛮多例的:
    <?php
    class CURL {
       var $callback = false;function setCallback($func_name) {
       $this->callback = $func_name;
    }function doRequest($method, $url, $vars) {
       $ch = curl_init();
       curl_setopt($ch, CURLOPT_URL, $url);
       curl_setopt($ch, CURLOPT_HEADER, 1);
       curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
       curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
       curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
       curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
       curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
       if ($method == 'POST') {
           curl_setopt($ch, CURLOPT_POST, 1);
           curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
       }
       $data = curl_exec($ch);
       curl_close($ch);
       if ($data) {
           if ($this->callback)
           {
               $callback = $this->callback;
               $this->callback = false;
               return call_user_func($callback, $data);
           } else {
               return $data;
           }
       } else {
           return curl_error($ch);
       }
    }function get($url) {
       return $this->doRequest('GET', $url, 'NULL');
    }function post($url, $vars) {
       return $this->doRequest('POST', $url, $vars);
    }
    }$a=new CURL();
    echo $a->post("http://wap.lenovomobile.com/cp/log/import.do",array("test"=>"1"));
    ?>
      

  5.   

    $url="http://wap.lenovomobile.com/cp/log/import.do";
    $ch = curl_init();
    echo "ch==".$ch."<br>";
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_POST,1);
    curl_setopt($ch,CURLOPT_POSTFIELDS,$params);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);$ret = curl_exec($ch);
    curl_close($ch);print_r($ret);
      

  6.   

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);这样执行的结果才会以string返回
      

  7.   

    你想干什么?用curl上传文件?
    那么你的 $params 是如何写的?
      

  8.   

    是的,我想用curl post数据到别的公司的服务器上。$params 参数是如下结果$flag = 0;
     //要post的数据 
    $argv = array(
    'userName'=>'mops',
    'password'=>'mops',
    'logDate'=>$BiginDate,
    'statisticsByBase64'=>$content); 
    //构造要post的字符串 
    foreach ($argv as $key=>$value) { 
    if ($flag!=0) {
    $params .= "&"; 
    $flag = 1; 

    $params.= $key."="; $params.= urlencode($value); 
    $flag = 1; 
      

  9.   

    不过,我刚才发现,好像没有编译curl进去。想问问各位zz。我怎么把模块编译进去?我已经把php.ini的extension=php_curl.dll前面的";"去掉 ,并且重启。可还是不可以,是不是还需要作其他操作?我不是太懂,求助各位zz.
      

  10.   

    win32系统?
    php_curl.dll CURL,客户端 URL 库函数库 需要:libeay32.dll,ssleay32.dll(已附带) 
    请把 libeay32.dll、ssleay32.dll 置于系统的搜索路径中curl_setopt($ch,CURLOPT_POSTFIELDS,$params);
    中的 $params 一般用关联数组较好,不必自行组装url参数串
      

  11.   

    哦,不是呢。linux
      下面是我用另外的方式 post数据。但好像也不行。各位zz看看阿。  function POSTDATA($ourl, $data)
    {
    global $sessionStr; $url = parse_url($ourl);
    if (!$url)
    {
    return array("FLAG"=>0,"MSG"=>"the url [ ${ourl} ] is not a valid httpUrl");
    } if (!isset($url['port'])) { $url['port'] = ""; } if (!isset($url['query'])) { $url['query'] = ""; }
    $encoded = ""; while (list($k,$v) = each($data))
    {
    $encoded .= ($encoded ? "&" : "");
    $encoded .= rawurlencode($k)."=".rawurlencode($v);
    } $fp = fsockopen($url['host'], $url['port'] ? $url['port'] : 80);
    echo "fp===".$fp."<br>";
    if (!$fp)
    {
    return array("FLAG"=>0,"MSG"=>"fail to open the url ${ourl}");
    } $tmp="";
    $tmp.=sprintf("POST %s%s%s HTTP/1.0\r\n", $url['path'], $url['query'] ? "?" : "", $url['query']);
    $tmp.="Host: $url[host]\r\n";
    $tmp.="Content-type: application/x-www-form-urlencoded\r\n";
    $tmp.="Content-Length: " . strlen($encoded) . "\r\n";
    if(!empty($sessionStr))
    {
    $tmp.=$sessionStr . "\r\n";
    } $tmp.="Connection: close\r\n\r\n";
    $tmp.="$encoded\r\n";
    fputs($fp,$tmp); $line = fgets($fp,1024);
    if (!eregi("^HTTP/1\.. 200", $line))
    {
    return array("FLAG"=>0,"MSG"=>$line);
    } $results = ""; 
    $inheader = 1;
    while(!feof($fp))
    {
    $line = fgets($fp,1024); if ($inheader && ($line == "\n" || $line == "\r\n"))
    {
    $inheader = 0;
    }
    elseif (!$inheader)
    {
    $results .= $line;
    }
    else
    {
    if(strcmp(strtolower(substr($line,0,10)),'set-cookie')==0)
    {
    $sessionStr=substr(trim($line),4);
    } }
    }
    fclose($fp); return array("FLAG"=>1,"MSG"=>$results);
    }//上面是post数据的函数。//下面是我的调用:
    $argv = array(
    'userName'=>'mop',
    'password'=>'mop();123',
    'logDate'=>$BiginDate,
    'statisticsByBase64'=>$content
    ); 
    $url="http://wap.lenovomobile.com/cp/log/import.do";
    $res=array();
    $res=POSTDATA($url,$argv);print_r($res);
    $sessionStr='';返回的结果是:HTTP/1.1 404 /cp/404.html
      

  12.   

    linux 有php_curl.dll吗?
      

  13.   

    呵呵。不好意思,错了。linux 需要下载curl包,安装。然后重新编译php环境。我现在想先用上面的 fsockopen传看。不过,好像不成功。能否先帮忙看看吗?curl 我先不用。等万一不行了,我再去安装,编译。:) 多谢各位zz.
      

  14.   

    今天我安装编译了curl模块,然后执行下面的
       $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
       curl_setopt($ch, CURLOPT_HEADER, 1);
       curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
       curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
       curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
       curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
       curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
       
       curl_setopt($ch, CURLOPT_POST, 1);
       curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
      
       $data = curl_exec($ch);
       curl_close($ch);返回结果竟然是 :HTTP/1.1 100 Continue HTTP/1.1 404 /cp/404.html Date: Wed, 08 Nov 2006 02:38:09 GMT Server: Apache Transfer-Encoding: chunked Content-Type: text/plain   请问各位zz,这是我这里写的不对吗?
      

  15.   

    最后我还是用socket解决,结帖