所以这就是我目前所拥有的,我正在尝试使用PHP / cURL创建一个将登录Pinger TextFree Web服务的脚本。
我不知道我缺少什么,我没有看到OAuth的HTTP事务。我已经读过一些关于它但我仍然迷失了。
有什么建议吗?
function sendRequest($url, $postorget, $fields = array(), $proxy)
{
$cookie_file = "cookies.txt";
//Initiate connection
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $header); // set url
//curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_URL, $url); // set url
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return the transfer
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // allow https
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)'); // random agent
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // automatically follow Location: headers (ie redirects)
curl_setopt($ch, CURLOPT_AUTOREFERER, 1); // auto set the referer in the event of a redirect
curl_setopt($ch, CURLOPT_MAXREDIRS, 5); // ibm likes to redirect a lot, make sure we dont get stuck in a loop
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file); // file to save cookies in
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file); // file to read cookies from
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 40); //timeout time for curl
//Check to see if a proxy is being used
if(isset($proxy)){
//Tell cURL you're using a proxy
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
//Set the proxy
curl_setopt($ch, CURLOPT_PROXY, $proxy);
}
//Check if request is POST or GET
if ($postorget == "post" OR $postorget == "POST")
{
curl_setopt($ch, CURLOPT_POST, true); // use POST
if (is_array($fields)){
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields)); // key => name gets turned into &key=name
} else {
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields); // &key=name passed in
}
} else {
curl_setopt($ch, CURLOPT_POST, false); // use GET
}
$content = curl_exec($ch); // return html content
$info = curl_getinfo($ch); // return transfer info
$error = curl_error($ch); // return any errors
curl_close($ch);
$request = array('content' => $content,
'error' => $error,
'info' => $info);
return $request;
}
//Login details
$username = "usernaem";
$password = "password";
//GET the initial login page
$initFields = "";
$initOutput = sendRequest("http://www.pinger.com/tfw/?t=1360619019053", "GET", $initFields);
echo "<textarea cols='100' rows='400'>";
print_r($initOutput);
echo "</textarea>";
//Login to pinger
$loginFields = "{\"username\":\"".$username."\",\"password\":\"".$password."\",\"clientId\":\"textfree-in-flash-web-free-1360619009-8CA1C5C1-38ED-2E31-3248-CB367450A20F\"}";
$loginOutput = sendRequest("https://api.pinger.com/1.0/web/login", "POST", $loginFields);
echo "<textarea cols='100' rows='400'>";
print_r($loginOutput);
echo "</textarea>";
答案 0 :(得分:-2)
我们在PHP / cURL脚本中注意到了这一部分,其中提到了用户名。
请检查代码的这一部分:
//Login details
$ username =“usernaem”; $ password =“password”;
您会注意到指定用户名的部分拼写错误
usernaem
请尝试更正此错误,这应该可以解决您的问题。