我在Windows Server 2016计算机上运行IIS-Webserver 10。 我想通过OKHTTP(多部分数据)从我的Android应用程序上传照片。
尝试这一点,我总是收到消息" 405 - 方法不允许"。 启用WebDav但得到相同的错误。
我该如何正确地做到这一点?
以下是我上传数据的代码
@Override
protected String doInBackground(Void... voids) {
File file = new File(fullFilepath);
OkHttpClient httpClient = new OkHttpClient();
Request.Builder builder = new Request.Builder();
builder.url(dmzServer + "Uploads/");
MultipartBody.Builder bodyBuilder = new MultipartBody.Builder();
bodyBuilder.addFormDataPart("test.jpeg", file.getName(), RequestBody.create(MediaType.parse("image/jpeg"), file));
MultipartBody body = bodyBuilder.build();
final RequestBody requestBody = ProgressHelper.withProgress(body, new ProgressUIListener() {
@Override
public void onUIProgressChanged(long numBytes, long totalBytes, float percent, float speed) {
publishProgress(percent);
}
});
builder.put(requestBody);
Call call = httpClient.newCall(builder.build());
call.enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
Log.e("CALL", e.getMessage());
}
@Override
public void onResponse(Call call, Response response) throws IOException {
Log.i("CALL", "response");
}
});
return null;
}
托马斯