我的应用程序中有一个字节数组,我从相机中获取。我需要使用Retrofit2将其发送到服务器。当我尝试发送它时,我得到SocketTimeoutException。我已尝试使用浏览器发送请求,一切正常。这是我的发送改造服务方法:
@Multipart
@POST("/userchange/setuserpic")
Call<AuthResponse> setUserPic(@Part("authToken") RequestBody authToken, @Part("userpic") RequestBody picture, @Part("extension") RequestBody extension);
我发送的服务如下:
private void handleActionSetUserPic(String authToken, byte[] picture, String extension) {
RequestBody token = RequestBody.create(MediaType.parse("multipart/form-data"), authToken);
RequestBody pic = RequestBody.create(MediaType.parse("multipart/form-data"), picture);
RequestBody ext = RequestBody.create(MediaType.parse("multipart/form-data"), extension);
Call<AuthResponse> request = mAuthApi.setUserPic(token, pic, ext);
try {
Response<AuthResponse> response = request.execute();
AuthResponse result = response.body();
Log.i("tag", result.toString());
} catch (IOException e) {
e.printStackTrace();
}
}
那么我做错了什么?