urlencoded用途的文件

urlencoded用途的文件

如何配置改造工作,如下图所示

android - 上载具有application/x-www-form-urlencoded用途的文件-LMLPHP

这是我的代码:

    // interface ImageUploadService

    @Multipart
    @POST("/api=upl_img_version_2&token={token}&img_cat=3&sum={sum}")
    Observable<ServerResponse> uploadAvatar(@Path("token") String token, @Path("sum") String sum,  @Part MultipartBody.Part file);
    ===========================================

    //File creating from selected URL
    File file = new File(path);

    // create RequestBody instance from file
    RequestBody requestFile = RequestBody.create(MediaType.parse("multipart/form-data"), file);

    // body part send to server
    MultipartBody.Part body = MultipartBody.Part.createFormData("file", file.getName(), requestFile);

    view.showLoadingDialog();
    imageUploadService.uploadAvatar(token, sum, body)
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new Subscriber<ServerResponse>() {
                        @Override
                        public void onCompleted() {
                            view.hideLoadingDialog();
                        }

                        @Override
                        public void onError(Throwable e) {
                            e.printStackTrace();
                            view.hideLoadingDialog();
                        }

                        @Override
                        public void onNext(ServerResponse serverResponse) {
                            Log.d("aaaaa", serverResponse.toString());
                        }
                    })


然后使用burp套件来捕获请求,并且与ios(工作)不同,我对此没有任何想法或关键字。谢谢

最佳答案

我刚刚找到了解决方案,并希望帮助某人面对同样的问题,而不是删除此问题。

这是工作代码:

interface ImageUploadService {
   //@Multipart
  @POST("/api=upl_img_version_2&token={token}&img_cat=3&sum={sum}")
  Observable<ServerResponse> uploadAvatar(@Path("token") String token, @Path("sum") String sum,  @Body RequestBody file); // @Part => @Body
}

///////////////////////////////
File file = new File(path);

// MediaType.parse("multipart/form-data")
RequestBody requestBody = RequestBody.create(MediaType.parse("application/octet-stream"), file);
imageUploadService.uploadAvatar(token, sum, requestBody)
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new Subscriber<ServerResponse>() {
                        @Override
                        public void onCompleted() {
                            view.hideLoadingDialog();
                        }

                        @Override
                        public void onError(Throwable e) {
                            e.printStackTrace();
                            view.hideLoadingDialog();
                        }

                        @Override
                        public void onNext(ServerResponse serverResponse) {
                            Log.d("aaaaa", serverResponse.toString());
                        }
                    })

关于android - 上载具有application/x-www-form-urlencoded用途的文件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45952155/

10-09 12:49