转换为PHP REST CURL POST
如何将此代码转换为PHP REST CURL POST转换为PHP REST CURL POST,php,rest,post,upload,onedrive,Php,Rest,Post,Upload,Onedrive,如何将此代码转换为PHP REST CURL POST POST https://apis.live.net/v5.0/me/skydrive/files?access_token=ACCESS_TOKEN Content-Type: multipart/form-data; boundary=A300x --A300x Content-Disposition: form-data; name="file"; filename="HelloWorld.txt" Content-Type: a
POST https://apis.live.net/v5.0/me/skydrive/files?access_token=ACCESS_TOKEN
Content-Type: multipart/form-data; boundary=A300x
--A300x
Content-Disposition: form-data; name="file"; filename="HelloWorld.txt"
Content-Type: application/octet-stream
Hello, World!
--A300x--
编辑:未阅读全部帖子,已修复。希望对您有所帮助:
<?php
$headers = array('token: pacexpressx1x2x3j' );
$data = array(
"STATUS" => "insert" ,
"NAME" => utf8_encode("Test integration 10"),
"COD_AREA" => "4",
"DESC_AREA_" => utf8_encode("info/IT"),
"JOB" => utf8_encode("TEST job"),
"COMPANY" => "4",
"DESC_COMPANY" => utf8_encode("XPTO1"),
"file" => '@/home/user/test.png');
$url = 'your_link';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$output = curl_exec($ch);
echo($output) . PHP_EOL;
curl_close($ch);
您最好阅读CURL:。通常情况下,如果答案中包含对代码意图的解释,以及在不介绍其他内容的情况下解决问题的原因,那么答案会更有帮助。
<?php
$headers = array('token: pacexpressx1x2x3j' );
$data = array(
"STATUS" => "insert" ,
"NAME" => utf8_encode("Test integration 10"),
"COD_AREA" => "4",
"DESC_AREA_" => utf8_encode("info/IT"),
"JOB" => utf8_encode("TEST job"),
"COMPANY" => "4",
"DESC_COMPANY" => utf8_encode("XPTO1"),
"file" => '@/home/user/test.png');
$url = 'your_link';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$output = curl_exec($ch);
echo($output) . PHP_EOL;
curl_close($ch);
echo 'Here is some more debugging info:';
echo "\n<hr />\n";
print_r($_FILES);
echo "\n<hr />\n";
print_r($_POST);
print "</pr" . "e>\n";
echo "\n<hr />\n";
// here you will record the file in your server... you can choose a directory if you want
file_put_contents($_FILES['file']['name'],file_get_contents($_FILES['file']['tmp_name']));