![](/img/trans.png)
[英]How to properly handle client “Connection: close” request on HTTP file server?
[英]How send the http post request with DataOutPutStream properly so server can handle it
我希望有人告诉我只写一个文件和一个带有另一种字节的文件有什么不同。
服务器使用,python3 flask
我想也许 android retrofit 等有用,但我想尝试使用经典方法 HTTPUrlConnection 所以我成功地将一个或多个字符串参数发送到服务器。 我也成功地将文件发送到服务器。 - 我的文件将只有 5 秒的音频或视频 mp4,由真正的 android 创建。
当我只尝试两个参数和一个字节列表 len(list) = 2 时,我可以取回我发送的文件,但是字节的 concat 样式无法实现。
但是当我将两者结合起来时,我发现当文件被切成多部分时,文件就无法恢复。
list= request.data.split(b"------------------------------")
newList= list[1:]
data = b""
for part in newList:
data += part
def createAudioFromDataReceived(fileName, data):
with open(fileName, 'wb') as wfile:
wfile.write(data)
public void writeFilesParamToDataOutputStream(HttpURLConnection conn, File file, String action) throws IOException {
byte[] buffer;
FileInputStream fileInputStream = new FileInputStream(file);
DataOutputStream dos = new DataOutputStream(conn.getOutputStream());
buffer = new byte[1024 * 1024];
int length = 0;
while ( ( length = fileInputStream.read( buffer ) ) > 0 ) {
dos.write(buffer, 0, length);
}
dos.flush();
fileInputStream.close();
dos.close();
}
//Bytes
byte[] bytes = "toSend".getBytes();
dos.write(bytes);
dos.write("------------------------------");
ops,之前看到的参考大致是这种如何将数据从服务器发送到Android?
我无法想象字节有很多“-”并且需要“/r/n”...
分隔符应该是类似的东西
String delimiter = "--aaWEdFXvDF--" + "\r\n";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.