我提供了以下api来提交照片或文字的项目更新
POST https://linktosite/api/projects/id/updates?limit=limit&offset=offset
Request
User Authenticated
HEADERS
Content-Type:multipart/form-data; boundary=__BOUNDARY__
BODY
--__BOUNDARY__
Content-Disposition: form-data; name="message"
foo bar2
--__BOUNDARY__
Content-Disposition: form-data; name="image"; filename="image.jpg"
Content-Type: image/jpeg
Content-Transfer-Encoding: base64
/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0a
HBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIy
MjIyMjIyMjIyMjIyMjIyMjIyjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAABAAEDASIA
AhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAf/xAAUEAEAAAAAAAAAAAAAAAAAAAAA/8QAFAEB
AAAAAAAAAAAAAAAAAAAAAP/EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAMAwEAAhEDEQA/AL+AD//Z
--__BOUNDARY__--
如果可能的话,我正在寻找一种无卷曲的解决方案。这就是我到目前为止所拥有的。它不断返回错误,我不知道应该在哪里通过用户身份验证
$destination = "https://linktosite/api/projects/". $projectid ."/updates?limit=limit&offset=offset";
$eol = "\r\n";
$data = '';
$mime_boundary=md5(time());
$data .= '--' . $mime_boundary . $eol;
$data .= 'Content-Disposition: form-data; name="message"' . $eol . $eol;
$data .= $_POST['message'] . $eol;
$data .= '--' . $mime_boundary . $eol;
$data .= 'Content-Disposition: form-data; name="image"; filename="image.jpg"' . $eol;
$data .= 'Content-Type: image/jpeg' . $eol;
$data .= 'Content-Transfer-Encoding: base64' . $eol . $eol;
$data .= chunk_split(base64_encode(
/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0a
HBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIy
MjIyMjIyMjIyMjIyMjIyMjIyjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAABAAEDASIA
AhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAf/xAAUEAEAAAAAAAAAAAAAAAAAAAAA/8QAFAEB
AAAAAAAAAAAAAAAAAAAAAP/EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAMAwEAAhEDEQA/AL+AD//Z
)) . $eol;
$data .= "--" . $mime_boundary . "--" . $eol . $eol; // finish with two eol's!!
$params = array('http' => array(
'method' => 'POST',
'header' => 'Content-Type: multipart/form-data; boundary=' . $mime_boundary . $eol,
'content' => $data
));
$ctx = stream_context_create($params);
$response = @file_get_contents($destination, FILE_TEXT, $ctx);
print_r($response);
这是我的html表单
<form action="" method="post" enctype="multipart/form-data">
<input id="file-input" name="files" type="file"/>
<input name="message" type="text" placeholder="Submit a update.."></input>
<input type="image" src="/img/arrows.png" border="0" alt="Submit" />
</form>