国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

java - Retrofit okHttp 上傳圖片總是不行
PHP中文網(wǎng)
PHP中文網(wǎng) 2017-04-18 09:30:28
0
6
419
PHP中文網(wǎng)
PHP中文網(wǎng)

認證0級講師

reply all(6)
PHPzhong

This is what I wrote @Part("image"; filename="image.png" ") RequestBody image

洪濤
  Map<String, RequestBody> photoRequestBodyMap = new HashMap<>();


        photoRequestBodyMap.put("Content", RequestBody.create(MediaType.parse("text/plain"), et_body.getText().toString()));

        for (int i = 0; i < picList.size(); i++) {
        
                File file = new File(picList.get(i));
                RequestBody requestBody = RequestBody.create(MediaType.parse("image/*"), file);
                
                String key = "image\";filename=\"" + file.getName();
                photoRequestBodyMap.put(key, requestBody);
                
            } catch (Exception e) {
            }
        }


        netApiInterface
                .postMoment(photoRequestBodyMap)

I am like this.

There are many opinions on the Internet about the key to be used when uploading images.
On my side, the actual test is that String key = "image";filename="" + file.getName(); works

Ty80

Method annotations only use POST, parameter annotations only use BODY, and MultipartBody is constructed separately for uploading.
Retrofit2.0’s support for uploading files is not that simple, you should get familiar with okhttp

Ty80

If you are using Retrofit2.0, then the Part annotation should be followed by MultipartBody.Part instead of RequestBody

阿神

http://m.blog.csdn.net/article/details?id=51511493 This is using okhttp as the background is php receiving

大家講道理

I also succeeded using httpclient, but when using retrofit, I still need to pass the token, and it never succeeded

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template