改进多部分请求返回空体

时间:2017-08-11 10:05:45

标签: android file-upload retrofit multipart

目前,我正在为我正在实习的公司开发一个Android应用程序。 我要做的是创建一个包含各种字段和图像的表单。

我使用Retrofit作为我的网络库,将表单数据提交给服务器。

我遵循了以下教程: Upload Dynamic amounts of file to server

Passing multiple parameters with @PartMap

我将它们合并为:

端点

@POST("/stockyard/api/add-dealer.php")
Call<ResponseBody> submitForm(@PartMap() Map<String, RequestBody> textDetails,
                              @Part List<MultipartBody.Part> files);

MainActivtiy

Call<ResponseBody> form = submitRequest.submitForm(formDetails,filesList);
    final ProgressDialog uploadProgress = new ProgressDialog(QuickAddDealer.this);
    uploadProgress.setTitle("Uploading");
    uploadProgress.setMessage("Please Wait while your data is uploaded");
    uploadProgress.create();
    uploadProgress.show();
    form.enqueue(new Callback<ResponseBody>() {
        @Override
        public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                uploadProgress.dismiss();
            try {
                Toast.makeText(QuickAddDealer.this, response.body().string(), Toast.LENGTH_SHORT).show();
            } catch (IOException e) {
                e.printStackTrace();
            }
            finish();

        }
        @Override
        public void onFailure(Call<ResponseBody> call, Throwable t) {
            Toast.makeText(QuickAddDealer.this,t.toString(), Toast.LENGTH_SHORT).show();
            uploadProgress.dismiss();
        }
    });

问题是请求成功,但服务器代码没有收到任何这些请求。每次响应都是空的。

我无法弄清楚这个问题。请帮忙。

P.S。之前,代码将执行OnFailure,响应“Too many follow up requests”,但数据将成功提交给服务器。但过了一段时间后,此错误停止显示,数据无法提交给服务器。

修改

记录的请求

  

08-12 11:22:13.021 30327-31511 / in.avprojects.formtest D / OkHttp: - &gt; POST https://glocar.in/developing/stockyard/api/add-dealer.php http / 1.1   08-12 11:22:13.021 30327-31511 / in.avprojects.formtest D / OkHttp:Content-Type:multipart / form-data;边界= 7d8bb6d6-ECAA-4e18-b219-0e02ffa04221   08-12 11:22:13.026 30327-31511 / in.avprojects.formtest D / OkHttp:内容长度:66335   08-12 11:22:13.054 30327-31511 / in.avprojects.formtest D / OkHttp: - 7d8bb6d6-ecaa-4e18-b219-0e02ffa04221   08-12 11:22:13.054 30327-31511 / in.avprojects.formtest D / OkHttp:Content-Disposition:form-data; NAME = “CREATED_BY”   08-12 11:22:13.054 30327-31511 / in.avprojects.formtest D / OkHttp:Content-Transfer-Encoding:二进制   08-12 11:22:13.054 30327-31511 / in.avprojects.formtest D / OkHttp:Content-Type:text / plain;字符集= utf-8的   08-12 11:22:13.054 30327-31511 / in.avprojects.formtest D / OkHttp:内容长度:2   08-12 11:22:13.054 30327-31511 / in.avprojects.formtest D / OkHttp:30   08-12 11:22:13.054 30327-31511 / in.avprojects.formtest D / OkHttp: - 7d8bb6d6-ecaa-4e18-b219-0e02ffa04221   08-12 11:22:13.054 30327-31511 / in.avprojects.formtest D / OkHttp:Content-Disposition:form-data; NAME = “dealer_latitude”   08-12 11:22:13.054 30327-31511 / in.avprojects.formtest D / OkHttp:Content-Transfer-Encoding:二进制   08-12 11:22:13.054 30327-31511 / in.avprojects.formtest D / OkHttp:Content-Type:text / plain;字符集= utf-8的   08-12 11:22:13.054 30327-31511 / in.avprojects.formtest D / OkHttp:内容长度:7   08-12 11:22:13.055 30327-31511 / in.avprojects.formtest D / OkHttp:25.5571   08-12 11:22:13.055 30327-31511 / in.avprojects.formtest D / OkHttp: - 7d8bb6d6-ecaa-4e18-b219-0e02ffa04221   08-12 11:22:13.055 30327-31511 / in.avprojects.formtest D / OkHttp:Content-Disposition:form-data; NAME = “dealer_longitude”   08-12 11:22:13.055 30327-31511 / in.avprojects.formtest D / OkHttp:Content-Transfer-Encoding:二进制   08-12 11:22:13.055 30327-31511 / in.avprojects.formtest D / OkHttp:Content-Type:text / plain;字符集= utf-8的   08-12 11:22:13.055 30327-31511 / in.avprojects.formtest D / OkHttp:内容长度:7   08-12 11:22:13.055 30327-31511 / in.avprojects.formtest D / OkHttp:77.1441   08-12 11:22:13.055 30327-31511 / in.avprojects.formtest D / OkHttp: - 7d8bb6d6-ecaa-4e18-b219-0e02ffa04221   08-12 11:22:13.055 30327-31511 / in.avprojects.formtest D / OkHttp:Content-Disposition:form-data; NAME =“添加 - 交易商提交”   08-12 11:22:13.055 30327-31511 / in.avprojects.formtest D / OkHttp:Content-Transfer-Encoding:二进制   08-12 11:22:13.055 30327-31511 / in.avprojects.formtest D / OkHttp:Content-Type:text / plain;字符集= utf-8的   08-12 11:22:13.055 30327-31511 / in.avprojects.formtest D / OkHttp:内容长度:3   08-12 11:22:13.055 30327-31511 / in.avprojects.formtest D / OkHttp:abc   08-12 11:22:13.055 30327-31511 / in.avprojects.formtest D / OkHttp: - 7d8bb6d6-ecaa-4e18-b219-0e02ffa04221   08-12 11:22:13.055 30327-31511 / in.avprojects.formtest D / OkHttp:Content-Disposition:form-data; NAME = “dealer_form_id”   08-12 11:22:13.055 30327-31511 / in.avprojects.formtest D / OkHttp:Content-Transfer-Encoding:二进制   08-12 11:22:13.055 30327-31511 / in.avprojects.formtest D / OkHttp:Content-Type:text / plain;字符集= utf-8的   08-12 11:22:13.055 30327-31511 / in.avprojects.formtest D / OkHttp:内容长度:6   08-12 11:22:13.055 30327-31511 / in.avprojects.formtest D / OkHttp:000566   08-12 11:22:13.055 30327-31511 / in.avprojects.formtest D / OkHttp: - 7d8bb6d6-ecaa-4e18-b219-0e02ffa04221   08-12 11:22:13.055 30327-31511 / in.avprojects.formtest D / OkHttp:Content-Disposition:form-data; NAME = “dealer_pics”;文件名= “IMG_20170811_105147.jpg”   08-12 11:22:13.055 30327-31511 / in.avprojects.formtest D / OkHttp:Content-Type:image / *   08-12 11:22:13.055 30327-31511 / in.avprojects.formtest D / OkHttp:内容长度:65118   `

0 个答案:

没有答案