php curl向另一个页面post,一个PHP CURL的POST提交遇到的问题
有一個接口
urlhttps://sendcloud.sohu.com/webapi/list.create.json
官方給的文檔是這樣的
* 請求接口(建議使用post請求,注意不要使用multipart-post):
/list.create
* 參數說明:
參數 類型 是否必須 說明 描述
api_user string 是 請求SC認證賬號
api_key string 是 請求 SC認證密碼
addres sstring 是 列表別稱地址 例如:developers@sendcloud.org或者 Developers
name string 是 列表名稱 不能大于16個中文字
description string 否 列表描述 不能大于85個中文字符
于是,我在命令行輸入這樣:
curl -d "api_user=*&api_key=*&address=runnerleer@maillist.sendcloud.org&name=demo&description=this is a demo list" https://sendcloud.sohu.com/webapi/list.create.json
提交正確,創建了一個郵件列表。
嘗試構造表單提交,同樣提交正確
html
但是,用PHP CURL提交,就出了問題,代碼如下:
php<?php
header('Content-Type:text/html;charset=utf-8');
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_URL, 'https://sendcloud.sohu.com/webapi/list.create.json');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = array(
'api_user' => '*',
'api_key' => '*',
'address' => 'runnerlee@maillist.sendcloud.org',
'name' => 'Abao新建的測試郵件列表',
'description' => '這是Abao新建的測試郵件列表',
);
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
if(false === $result=curl_exec($ch)) {
echo 'false:
';
}
var_dump(json_decode($result,true));
curl_close($ch);
這時候總是返回 bad username/password,如果直接在瀏覽器打開接口的url也是現實bad username/password。
所以我猜測是數據沒有提交上去。
百度了說設置curl_setopt($ch,CURLOPT_VERIFYHOST,true),但我一設置就報錯
Notice: curl_setopt(): CURLOPT_SSL_VERIFYHOST no longer accepts the value 1, value 2 will be used instead in F:\www\sendCloud\demo.php on line 13
更加奇怪的是用同樣的代碼,調用/mail.send.json也就是發送郵件的接口,卻能夠正常提交。
請各位幫忙看看,十分感謝!
總結
以上是生活随笔為你收集整理的php curl向另一个页面post,一个PHP CURL的POST提交遇到的问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 筑方装饰集团装修整屋包括玄关吗?
- 下一篇: 动态规划算法php,php算法学习之动态