1
我有這樣的代碼上傳文件
connection.setRequestMethod("POST");
connection.setRequestProperty("Connection", "Keep-Alive");
connection.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
outputStream = new DataOutputStream(connection.getOutputStream());
outputStream.writeBytes(twoHyphens + boundary + lineEnd);
outputStream.writeBytes("Content-Disposition: form-data; name=\"uploadedfile\";filename=\"" + pathToOurFile +"\"" + lineEnd);
outputStream.writeBytes(lineEnd);
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
buffer = new byte[bufferSize];
我使用這個代碼將文件保存到我的PHP服務器, 我需要的是額外增加POST
時發送額外的POST參數在Android的服務器例如call=sendfile
參數,這樣我就可以在PHP這樣的閱讀:
<?php
require "conn.php";
require "helper.php";
$call = $_POST["call"]; // this should return sendfile
if($_FILES["uploadedfile"]["name"]) {
.....
}
?>
我怎樣才能做到這一點?