php http請求有關問題

來源:互聯網
上載者:User
php http請求問題
錯誤資訊:{"errcode":41001,"errmsg":"access_token missing"}
//發送POST請求
$url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=";
$access_token = "bz6LKNCiQN5fHDZNJwWbCiPXqRkrlkBUcBGwb3MlM-tmnXK6TGsHGbsETwcOXmezlIouHdD7Rv3g9aLicuF-gA";
$url = $url . urlencode($access_token);
echo "請求url:" . $url ."
";
//要請求的內容
$data['action_name'] = "QR_LIMIT_SCENE";
$scene['scene_id'] = 10;
$action_info['scene'] = $scene;
$data['action_info'] = $action_info;
$data = json_encode($data);
echo "請求參數:" . $data ."
";

//url
$url_info = parse_url($url);
var_dump($url_info);
echo "
";
if(!isset($url_info['port']))
{
$url_info['port'] = 80;
//類比http要求標頭
$request .= "POST ".$url_info['path']." HTTP/1.1\n";
$request .= "Host: ".$url_info['host']."\n";
$request .= "Content-type: application/x-www-form-urlencoded\n";
$request .= "Content-length: ".strlen($data)."\n";
$request .= "Connection: close\n";
$request .= "\n";
$request .= $data."\n";
}

$fp = fsockopen($url_info["host"], $url_info["port"]);
fputs($fp, $request);//把HTTP頭髮送出去

$inheader = 1;
while(!feof($fp))
{
//$result 是提交後返回的資料
$result .= fgets($fp, 1024);
}
echo $result;
fclose($fp);
?>
------解決方案--------------------
41001 缺少access_token參數

返回碼說明
------解決方案--------------------
$fp = fsockopen($url_info["host"], $url_info["port"]);

$request .= "POST ".$url_info['path']." HTTP/1.1\n";
$request .= "Host: ".$url_info['host']."\n";
$request .= "Content-type: application/x-www-form-urlencoded\n";
$request .= "Content-length: ".strlen($data)."\n";
$request .= "Connection: close\n";
$request .= "\n";
$request .= $data."\n";
裡沒有發現有token的資訊。

------解決方案--------------------
$request .= "POST ".$url_info['path']." HTTP/1.1\n";
這裡填寫帶路徑和參數的目標頁名稱,比如
/cgi-bin/qrcode/create?access_token=?????
無論是 get 還是 post 方式,都是這樣寫
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.