简体   繁体   English

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

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

The SSH command I'm currently using in Terminal is: 我当前在Terminal中使用的SSH命令是:

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

I first login to my developer account and then download the cookies by a Chrome extension; 我首先登录我的开发者帐户,然后通过Chrome扩展程序下载cookie; following that, I upload the cookies.txt file to the same path I run the SSH command and easily mirror the file to my server. 之后,我将cookies.txt文件上传到运行SSH命令的相同路径,并轻松地将该文件镜像到我的服务器。 Now, I would like to do the same job with a PHP script. 现在,我想使用PHP脚本执行相同的工作。 I tried this code but didn't work. 我尝试了这段代码,但是没有用。

<?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;
?>

Any help/ideas would be greatly appreciated 任何帮助/想法将不胜感激

UPDATE: I updated my code the below code but: 更新:我更新了下面的代码,但是:

  1. If I use CURLOPT_USERPWD option I get "401 Authorization Required" although I define the correct user&pass 如果我使用CURLOPT_USERPWD选项,尽管定义了正确的用户名和密码,但我仍获得“ 401授权要求”
  2. If I use CURLOPT_COOKIEFILE option I get "403 Forbidden" although the cookies.txt is not expired! 如果我使用CURLOPT_COOKIEFILE选项,尽管cookies.txt没有过期,但我得到了“ 403 Forbidden”!

The live Link 实时链接

$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;

Let's have a look whats missing in your curl. 让我们看看你的卷发中缺少什么。

-L = follow redirects -L =跟随重定向

curl_setopt($cSession, CURLOPT_FOLLOWLOCATION, true);

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

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

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