王者荣耀登陆异常点链接就要重新登陆,什么原因

Android Retrofit 框架上传多张图片的方法详解_Android开发-织梦者
当前位置:&>&&>& > Android Retrofit 框架上传多张图片的方法详解
Android Retrofit 框架上传多张图片的方法详解
解决的方法是:使用Retrofit的MulipartTypedOutput
接口声明如下,注意此时不要再使用@FormUrlEncoded 和@Multipart 注解了
@POST(PATH + &submitOrderExt.do&)public void submitOrderMul(@Body MultipartTypedOutput multipartTypedOutput,BaseCallback&BaseCallbackModel& baseCallback);
MulipartTypedOutput 参数的装配示例代码如下:
/// 新的实现demoMultipartTypedOutput multipartTypedOutput = new MultipartTypedOutput();multipartTypedOutput.addPart(&stID&, new TypedString(stID));multipartTypedOutput.addPart(&stName&, new TypedString(stName));multipartTypedOutput.addPart(&uID&, new TypedString(uID));multipartTypedOutput.addPart(&uLoginMail&, new TypedString(uLoginMail));multipartTypedOutput.addPart(&areaID&, new TypedString(areaID));multipartTypedOutput.addPart(&areaName&, new TypedString(areaName));multipartTypedOutput.addPart(&oUserName&, new TypedString(oUserName));multipartTypedOutput.addPart(&oUserTel&, new TypedString(oUserTel));multipartTypedOutput.addPart(&oAddress&, new TypedString(oAddress));multipartTypedOutput.addPart(&oRepairContent&, new TypedString(oRepairContent));multipartTypedOutput.addPart(&oTimeStart&, new TypedString(mTimeStart));multipartTypedOutput.addPart(&oTimeEnd&, new TypedString(mTimeEnd));for (Map.Entry&String, Uri& entry : oSceneImgUriMap.entrySet()) {multipartTypedOutput.addPart(&oSceneImg&, new TypedFile(&image/jpeg&, new File(GetPathFromUri4kitkat.getPath(OrderActivity.this, entry.getValue()))));}if(null != voiceFile){multipartTypedOutput.addPart(&oVoice&, voiceFile);}
有说Retrofit 2.0.0-beta1 之后MultipartTypedOutput 不再使用转而使用@PartMap
MultipartTypedOutputno longer exists in Retrofit 2.0.0-beta1
For those who want to upload multiple images now can use with@PartMap, reference linkjavadoc
参考出处:
[1]/questions//android-retrofit-post-request-with-json-payload-and-images-attached
[2]/questions//retrofit-multiple-images-attached-in-one-multipart-request/60556
这些内容可能对你也有帮助
更多可查看Android开发列表页。
猜您也会喜欢这些文章问题对人有帮助,内容完整,我也想知道答案
问题没有实际价值,缺少关键内容,没有改进余地
这是我的Activity
public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Observable&Object& a = fileRetrofit().create(ApiStores.class).addCase2("123", 1234);
a.subscribeOn(Schedulers.io()).subscribe(new Consumer&Object&() {
public void accept(Object o) throws Exception {
public static Retrofit mFileR
public static Retrofit fileRetrofit(){
if (mFileRetrofit == null) {
OkHttpClient.Builder builder = new OkHttpClient.Builder()
.addInterceptor(new LoggingInterceptor());
OkHttpClient okHttpClient = builder.build();
mFileRetrofit = new Retrofit.Builder()
.baseUrl(ApiStores.BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.client(okHttpClient)
return mFileR
public interface ApiStores {
String BASE_URL = "http://123.12.123.123/";
@Multipart
@POST("qwe/asd")
Observable&Object& addCase2(@Part("tag") String tag, @Part("tag2") int tag2);
一下是LOG”request
Sending request http://123.12.123.123/qwe/asd on null
--369f49f5-597d-4aa2-9c5e-86eccda84c88
Content-Disposition: form- name="tag"
Content-Transfer-Encoding: binary
Content-Type: application/ charset=UTF-8
Content-Length: 5
--369f49f5-597d-4aa2-9c5e-86eccda84c88
Content-Disposition: form- name="tag2"
Content-Transfer-Encoding: binary
Content-Type: application/ charset=UTF-8
Content-Length: 4
--369f49f5-597d-4aa2-9c5e-86eccda84c88--
可以看到content-length为5, 即为“123”的长度,两边的双引号也被发送过去了
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
“@Part(“data”) String des”在Post请求中默认的Content-Type类型是“application/json”,这就说明我们在接口中不能再使用@Part注解了
@Multipart@POST("userPhoto")Observable&BaseHttpResult&String&& uploadMultipleTypeFile(@PartMap Map&String, RequestBody& params);
Map&String, RequestBody& bodyMap = new HashMap&&();bodyMap.put("photo"; filename=""+file.getName(), RequestBody.create(MediaType.parse("image/png"),file));bodyMap.put("userId", toRequestBody(userId));bodyMap.put("serialNumber", toRequestBody(serialNumber));
public static RequestBody toRequestBody(String value) {
RequestBody requestBody = RequestBody.create(MediaType.parse("text/plain"), value);
return requestB
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
造成的主要原因有两个:1、retrofit并不内置String的Converter,只有在Url、Header、普通表单字段相关的注解才会默认处理成String。2、你注册了GsonConverter,而GsonConverter是不会判断能不能处理该类型的,全部转成json,而String在json里就是 "String"的形式,所以长度变成5,Content-Type头是application/ charset=UTF-8
同步到新浪微博
分享到微博?
你好!看起来你挺喜欢这个内容,但是你还没有注册帐号。 当你创建了帐号,我们能准确地追踪你关注的问题,在有新答案或内容的时候收到网页和邮件通知。还能直接向作者咨询更多细节。如果上面的内容有帮助,记得点赞 (????)? 表示感谢。
明天提醒我
关闭理由:
删除理由:
忽略理由:
推广(招聘、广告、SEO 等)方面的内容
与已有问题重复(请编辑该提问指向已有相同问题)
答非所问,不符合答题要求
宜作评论而非答案
带有人身攻击、辱骂、仇恨等违反条款的内容
无法获得确切结果的问题
非开发直接相关的问题
非技术提问的讨论型问题
其他原因(请补充说明)
我要该,理由是:
扫扫下载 App问题对人有帮助,内容完整,我也想知道答案
问题没有实际价值,缺少关键内容,没有改进余地
这是我的Activity
public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Observable&Object& a = fileRetrofit().create(ApiStores.class).addCase2("123", 1234);
a.subscribeOn(Schedulers.io()).subscribe(new Consumer&Object&() {
public void accept(Object o) throws Exception {
public static Retrofit mFileR
public static Retrofit fileRetrofit(){
if (mFileRetrofit == null) {
OkHttpClient.Builder builder = new OkHttpClient.Builder()
.addInterceptor(new LoggingInterceptor());
OkHttpClient okHttpClient = builder.build();
mFileRetrofit = new Retrofit.Builder()
.baseUrl(ApiStores.BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.client(okHttpClient)
return mFileR
public interface ApiStores {
String BASE_URL = "http://123.12.123.123/";
@Multipart
@POST("qwe/asd")
Observable&Object& addCase2(@Part("tag") String tag, @Part("tag2") int tag2);
一下是LOG”request
Sending request http://123.12.123.123/qwe/asd on null
--369f49f5-597d-4aa2-9c5e-86eccda84c88
Content-Disposition: form- name="tag"
Content-Transfer-Encoding: binary
Content-Type: application/ charset=UTF-8
Content-Length: 5
--369f49f5-597d-4aa2-9c5e-86eccda84c88
Content-Disposition: form- name="tag2"
Content-Transfer-Encoding: binary
Content-Type: application/ charset=UTF-8
Content-Length: 4
--369f49f5-597d-4aa2-9c5e-86eccda84c88--
可以看到content-length为5, 即为“123”的长度,两边的双引号也被发送过去了
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
“@Part(“data”) String des”在Post请求中默认的Content-Type类型是“application/json”,这就说明我们在接口中不能再使用@Part注解了
@Multipart@POST("userPhoto")Observable&BaseHttpResult&String&& uploadMultipleTypeFile(@PartMap Map&String, RequestBody& params);
Map&String, RequestBody& bodyMap = new HashMap&&();bodyMap.put("photo"; filename=""+file.getName(), RequestBody.create(MediaType.parse("image/png"),file));bodyMap.put("userId", toRequestBody(userId));bodyMap.put("serialNumber", toRequestBody(serialNumber));
public static RequestBody toRequestBody(String value) {
RequestBody requestBody = RequestBody.create(MediaType.parse("text/plain"), value);
return requestB
分享到微博?
Hi,欢迎来到 SegmentFault 技术社区!⊙▽⊙ 在这里,你可以提出编程相关的疑惑,关注感兴趣的问题,对认可的回答投赞同票;大家会帮你解决编程的问题,和你探讨技术更新,为你的回答投上赞同票。
明天提醒我
关闭理由:
删除理由:
忽略理由:
推广(招聘、广告、SEO 等)方面的内容
与已有问题重复(请编辑该提问指向已有相同问题)
答非所问,不符合答题要求
宜作评论而非答案
带有人身攻击、辱骂、仇恨等违反条款的内容
无法获得确切结果的问题
非开发直接相关的问题
非技术提问的讨论型问题
其他原因(请补充说明)
我要该,理由是:
扫扫下载 App

我要回帖

更多关于 王者荣耀ipad登陆失败 的文章

 

随机推荐