$.ajax({
type: "post",
    url: url,
    data:{"account":$.trim($('#account').val()),"password":$.trim($("#passwd").val())},
    contentType:'application/x-www-form-urlencoded; charset=UTF-8',
    dataType:"json",
    success: function(data){}以下是自己写的php代码,,远程一直无法获取用户名信息
$url = $url  //调用接口的平台服务地址
$post_string = array('account'=>'admin','password'=>'admin');
$ch = curl_init();
$this_header = array(
"content-type: application/x-www-form-urlencoded; 
charset=UTF-8"
);
$cookieFile ='cookie.tmp';
curl_setopt($ch,CURLOPT_HTTPHEADER,$this_header);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_COOKIEFILE, $cookieFile); //同时发送Cookie
curl_setopt($ch,CURLOPT_COOKIEJAR, $cookieFile); // 把返回来的cookie信息保存在文件中
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$result = curl_exec($ch);
echo var_dump($result);

解决方案 »

  1.   

    参考地址
    http://java-er.com/blog/php-high-img/
      

  2.   


    <?php
    $url = $url  //调用接口的平台服务地址
    $post_string = array('account'=>'admin','password'=>'admin');
    $ch = curl_init();
    /*$this_header = array(
    "content-type: application/x-www-form-urlencoded; 
    charset=UTF-8"
    );*/
    $cookieFile ='cookie.tmp';
    //curl_setopt($ch,CURLOPT_HTTPHEADER,$this_header);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch,CURLOPT_COOKIEFILE, $cookieFile); //同时发送Cookie
    curl_setopt($ch,CURLOPT_COOKIEJAR, $cookieFile); // 把返回来的cookie信息保存在文件中
    curl_setopt($ch,CURLOPT_POST, true); // 加這句
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_string));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    $result = curl_exec($ch);
    echo var_dump($result);
    ?>