Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

通过PUT方法 发送文件到服务器 #96

Open
hainuo opened this issue Jul 15, 2020 · 2 comments
Open

通过PUT方法 发送文件到服务器 #96

hainuo opened this issue Jul 15, 2020 · 2 comments

Comments

@hainuo
Copy link

hainuo commented Jul 15, 2020

https://developer.apple.com/documentation/appstoreconnectapi/uploading_assets_to_app_store_connect#3591286

在跟苹果应用商店对接时,需要PUT上传文件,但是目前没有发现何种方式可以不需要key上传一个文件到苹果服务器

@twose
Copy link
Member

twose commented Mar 8, 2021

没懂 是否有HTTP包示例

saber更适合做爬虫而不是上传...

@hainuo
Copy link
Author

hainuo commented Mar 19, 2021

protected function putFile($url, $path, $contentType)
    {
        $header = [
            "Content-Type: " . $contentType,
            "Content-Length: " . filesize($path)
        ];
        return $this->curlPut($url, $path, $header);
    }
function curlPut($destUrl, $sourceFileDir, $headerArr = [], $timeout = 20)
    {
        $ch = curl_init(); //初始化curl
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //返回字符串,而不直接输出
        curl_setopt($ch, CURLOPT_URL, $destUrl); //设置put到的url
        curl_setopt($ch, CURLOPT_HEADER, 1); //定义是否显示状态头 1:显示 ; 0:不显示 
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArr);
        curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //不验证对等证书
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); //不检查服务器SSL证书

        curl_setopt($ch, CURLOPT_PUT, true); //设置为PUT请求
        curl_setopt($ch, CURLOPT_INFILE, fopen($sourceFileDir, 'rb')); //设置资源句柄
        curl_setopt($ch, CURLOPT_INFILESIZE, filesize($sourceFileDir));

        $response = curl_exec($ch);

        if ($error = curl_error($ch)) {
            $bkArr = [
                'code' => 0,
                'msg' => $error,
            ];
        } else {
            $bkArr = [
                'code' => 1,
                'msg' => 'ok',
                'resp' => $response,
            ];
        }

        curl_close($ch); // 关闭 cURL 释放资源

        return $bkArr;
    }
$returnPutFile = $this->putFile($appScreenshot['data']['attributes']['uploadOperations'][0]['url'], $path, $appScreenshot['data']['attributes']['uploadOperations'][0]['requestHeaders'][0]['value']);

上面是后来用curl自己写的一个, 就是将一个文件直接作为body上传

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants