我使用put请求上传图片并使用Okhttp服务器,请求与邮递员一起正常工作,但是通过android它给了我错误的请求 我已经实现了这里讨论的方法https://stackoverflow.com/a/23784452/9145387
请帮助我排序这个....先谢谢
getCollAsync = () => {
return Promise.combine({
dbase: ({ dbURL }) => { return mongoClient.connect(dbURL); },
collInfos: ({ dbase }) => {
return dbase.db(this.databaseName)
.listCollections().toArray();
},
}, { dbURL: this.URL }).then(({ dbase, collInfos }) => {
return Promise.resolve(collInfos.map((info) => {
return dbase.collection(info.name);
}));
}).then((collections) => {
return Promise.all(collections.map((collection) => {
return collection.find({}).toArray();
}))
});
}
答案 0 :(得分:0)
尝试此操作以重置超时:
OkHttpClient client = new OkHttpClient();
client.setConnectTimeout(60, TimeUnit.SECONDS);
client.setReadTimeout(60, TimeUnit.SECONDS);
答案 1 :(得分:0)
错误在请求正文中。
RequestBody requestBody = new MultipartBuilder()
.type(MultipartBuilder.FORM)
.addFormDataPart("file", file.getName(),
RequestBody.create(MediaType.parse("image/jpg"), file))
.addFormDataPart(caseId+"_audio", caseId+"_audio",
RequestBody.create(MediaType.parse("audio/*"), Audio))
.build();
更改了此行
.addFormDataPart(caseId+"_audio", caseId+"_audio",
RequestBody.create(MediaType.parse("audio/*"), Audio))
.build();
到
.addFormDataPart(caseId+"_audio", Audio.getName(),
RequestBody.create(MediaType.parse("audio/*"), Audio))
.build();