繁体   English   中英

如何将该cURL命令转换为PHP?

[英]How can I convert this cURL command to PHP?

我当前在Terminal中使用的SSH命令是:

curl -L -b cookies.txt http://www.dropbox.com/s/8lu0nutt4tgpkku/jbtools.ipa -o iOS9_beta.ipsw

我首先登录我的开发者帐户,然后通过Chrome扩展程序下载cookie; 之后,我将cookies.txt文件上传到运行SSH命令的相同路径,并轻松地将该文件镜像到我的服务器。 现在,我想使用PHP脚本执行相同的工作。 我尝试了这段代码,但是没有用。

<?php
$cSession = curl_init(); 
curl_setopt($cSession,CURLOPT_URL,"http://www.dropbox.com/s/8lu0nutt4tgpkku/jbtools.ipa");
curl_setopt($cSession, CURLOPT_COOKIEJAR, 'cookies.txt');
curl_setopt($cSession, CURLOPT_COOKIEFILE, 'cookies.txt');
curl_setopt($cSession,CURLOPT_RETURNTRANSFER,true);
curl_setopt($cSession,CURLOPT_HEADER, false); 
$result=curl_exec($cSession);
curl_close($cSession);
echo $result;
?>

任何帮助/想法将不胜感激

更新:我更新了下面的代码,但是:

  1. 如果我使用CURLOPT_USERPWD选项,尽管定义了正确的用户名和密码,但我仍获得“ 401授权要求”
  2. 如果我使用CURLOPT_COOKIEFILE选项,尽管cookies.txt没有过期,但我得到了“ 403 Forbidden”!

实时链接

$cSession = curl_init(); 
curl_setopt($cSession,CURLOPT_URL,"http://adcdownload.apple.com/Safari/Safari_10_for_OS_X_El_Capitan_and_Yosemite_beta_5/Safari_10_for_OS_X_El_Capitan_beta_5.dmg");
curl_setopt($cSession, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($cSession, CURLOPT_USERPWD, "MyUser:MyPass");
// curl_setopt($cSession, CURLOPT_COOKIEJAR, 'cookies.txt');
//curl_setopt($cSession, CURLOPT_COOKIEFILE, 'cookies.txt');
curl_setopt($cSession,CURLOPT_RETURNTRANSFER,true);
curl_setopt($cSession,CURLOPT_HEADER, false); 
$result=curl_exec($cSession);
curl_close($cSession);
echo $result;

让我们看看你的卷发中缺少什么。

-L =跟随重定向

curl_setopt($cSession, CURLOPT_FOLLOWLOCATION, true);

参见: http : //php.net/manual/en/function.curl-setopt.php

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM