android - 使用curl将android本地文件上传到远程网络服务器

标签 android linux curl

我正在尝试使用 curl 从我的 Android 设备上传文件。该文件位于

/sdcard/Download/fileToUpload.txt

下面是我通过 Terminal 使用的命令应用:-

curl -i -X POST -H "Content-Type: multipart/form-data" \            
                -F "content=@/sdcard/Download/fileToUpload.txt" \
                 http://192.168.1.104/android/upload.php

我已经测试了在桌面上运行良好的相同命令。 过去几个小时我一直在敲头。请让我知道哪里出了问题。

P.S: I'm worried where this question would be a stupid one.

edit:- I don't want to root my device. As this would be my last option.

最佳答案

您可以使用 Retrofit ,一个非常强大的 Android 库,提供有用的 API 以通过 http 请求与服务器交互。

在特定情况下,您可以根据接口(interface)文件中的此模板在多部分表单数据中使用帖子

@Multipart
@POST("/android/upload.php")
Call<Void> sendFiles(
        @Part MultipartBody.Part[] files
);

然后,您必须在您的特定代码中实例化改造:

Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(endpoint)
            .build();

关于android - 使用curl将android本地文件上传到远程网络服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53173842/

相关文章:

c++ - curl 在线程调用中崩溃

Android库项目无法启动?

java - 我不明白 eclipse 的错误

Android 即时应用程序 : Migration of existing multidex app to base/feature module?

linux - 编译 libgcc xgcc 错误

c++ - 在 gcc linux x86-64 C++ 中,(p+x)-x 是否总是为指针 p 和整数 x 生成 p

php - 尝试访问 soap 网络服务器时出现 cURL 错误 58

android - 使用 AppCompatLibrary 从 fragment 中获取 ActionBar

c - 奇怪的 mmap 行为

symfony - HWIOAuthBundle - SSL 证书