PHP 卷曲请求 - Diawi API
PHP Curl Request - Diawi API
我正在努力让我的 Curl 请求正常工作。该代码的目的是使用他们的 API 将文件上传到 diawi.com。这是我第一次尝试使用 curl,我不确定语法是否正确。
这是我的代码:
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://upload.diawi.com/',
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"content-type: multipart/form-data"
),
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.2 (KHTML, like Gecko) Chrome/22.0.1216.0 Safari/537.2',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => array(
token => 'token',
file => 'http://example.com/apps/myapp.ipa',
find_by_udid => 0,
wall_of_apps => 0,
callback_url => 'http://www.example.com/apps/diawi_response.php',
callback_email => 'me@company.com'
)
));
$resp = curl_exec($curl);
curl_close($curl);
echo $resp;
目前我得到的回复是 "No file uploaded"。
这是来自文档的示例请求:
$ curl https://upload.diawi.com/ -F token='TOKEN' \
-F file=@MyApp.ipa \
-F find_by_udid=0 \
-F wall_of_apps=1 \
-F password='installation password' \
-F comment='Comment on the build' \
-F callback_url='http://www.example.com/my-diawi-callback-url' \
-F callback_email='me@company.com'
如果您能给我任何帮助,我们将不胜感激。
测试代币:MrdS5g9MpZhKn8jlJNuANRlmPuSBkBxWX1LTIptn8p
使用此来源。
<?php
ini_set('display_errors', 1);
$url = "https://upload.diawi.com/";
$filename = realpath('./ESFileExplorer.apk');
if ($filename != '')
{
$headers = array("Content-Type: multipart/form-data"); // cURL headers for file uploading
$postfields = array(
"token" => 'YOUR-TOKEN',
"file" => new CurlFile( $filename ),
"find_by_udid" => 0,
"wall_of_apps" => 1,
"callback_email" => 'xxxxx@gmail.com'
);
$ch = curl_init();
$options = array(
CURLOPT_URL => $url,
CURLOPT_HEADER => true,
CURLOPT_POST => 1,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POSTFIELDS => $postfields,
CURLOPT_USERAGENT => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:47.0) Gecko/20100101 Firefox/47.0'
); // cURL options
curl_setopt_array($ch, $options);
curl_exec($ch);
if(!curl_errno($ch))
{
// echo $ch;
$info = curl_getinfo($ch);
if ($info['http_code'] == 200)
$errmsg = "File uploaded successfully";
// print_r($info);
}
else
{
$errmsg = curl_error($ch);
}
curl_close($ch);
}
else
{
$errmsg = "Please select the file";
}
echo $errmsg;
?>
我得到的结果
HTTP/1.1 100 Continue HTTP/1.1 200 OK Server: nginx Content-Type: application/json Transfer-Encoding: chunked Connection: keep-alive Vary: Accept-Encoding Cache-Control: no-cache Date: Tue, 26 Jul 2016 19:40:33 GMT Strict-Transport-Security: max-age=15768000 {"job":"U37Nq7ta3Q711AsbvYrODFfvTLoyNwY4XslCFI7oV0"}File uploaded successfully
我正在努力让我的 Curl 请求正常工作。该代码的目的是使用他们的 API 将文件上传到 diawi.com。这是我第一次尝试使用 curl,我不确定语法是否正确。
这是我的代码:
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://upload.diawi.com/',
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"content-type: multipart/form-data"
),
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.2 (KHTML, like Gecko) Chrome/22.0.1216.0 Safari/537.2',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => array(
token => 'token',
file => 'http://example.com/apps/myapp.ipa',
find_by_udid => 0,
wall_of_apps => 0,
callback_url => 'http://www.example.com/apps/diawi_response.php',
callback_email => 'me@company.com'
)
));
$resp = curl_exec($curl);
curl_close($curl);
echo $resp;
目前我得到的回复是 "No file uploaded"。
这是来自文档的示例请求:
$ curl https://upload.diawi.com/ -F token='TOKEN' \
-F file=@MyApp.ipa \
-F find_by_udid=0 \
-F wall_of_apps=1 \
-F password='installation password' \
-F comment='Comment on the build' \
-F callback_url='http://www.example.com/my-diawi-callback-url' \
-F callback_email='me@company.com'
如果您能给我任何帮助,我们将不胜感激。
测试代币:MrdS5g9MpZhKn8jlJNuANRlmPuSBkBxWX1LTIptn8p
使用此来源。
<?php
ini_set('display_errors', 1);
$url = "https://upload.diawi.com/";
$filename = realpath('./ESFileExplorer.apk');
if ($filename != '')
{
$headers = array("Content-Type: multipart/form-data"); // cURL headers for file uploading
$postfields = array(
"token" => 'YOUR-TOKEN',
"file" => new CurlFile( $filename ),
"find_by_udid" => 0,
"wall_of_apps" => 1,
"callback_email" => 'xxxxx@gmail.com'
);
$ch = curl_init();
$options = array(
CURLOPT_URL => $url,
CURLOPT_HEADER => true,
CURLOPT_POST => 1,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POSTFIELDS => $postfields,
CURLOPT_USERAGENT => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:47.0) Gecko/20100101 Firefox/47.0'
); // cURL options
curl_setopt_array($ch, $options);
curl_exec($ch);
if(!curl_errno($ch))
{
// echo $ch;
$info = curl_getinfo($ch);
if ($info['http_code'] == 200)
$errmsg = "File uploaded successfully";
// print_r($info);
}
else
{
$errmsg = curl_error($ch);
}
curl_close($ch);
}
else
{
$errmsg = "Please select the file";
}
echo $errmsg;
?>
我得到的结果
HTTP/1.1 100 Continue HTTP/1.1 200 OK Server: nginx Content-Type: application/json Transfer-Encoding: chunked Connection: keep-alive Vary: Accept-Encoding Cache-Control: no-cache Date: Tue, 26 Jul 2016 19:40:33 GMT Strict-Transport-Security: max-age=15768000 {"job":"U37Nq7ta3Q711AsbvYrODFfvTLoyNwY4XslCFI7oV0"}File uploaded successfully