1.这可能是okhttp3里面的问题
错误的写法
private void getSingProject(String project_inner_id) {
GetSingleProjectRequest getSingleProjectRequest = new GetSingleProjectRequest();
getSingleProjectRequest.setCc(new GetSingleProjectRequest.CcBean(SPUtils.getMyGuid(MyApplication.context)));
getSingleProjectRequest.setPc(new GetSingleProjectRequest.PcBean((project_inner_id)));
Log.e(TAG, "获取单个项目详情" + gson.toJson(getSingleProjectRequest) + SPUtils.getToken(this));
MyApplication.mibeeAPI.getSingleProject2(getSingleProjectRequest, SPUtils.getToken(MyApplication.context)).enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
try {
if (response != null) {
if(response.body!=null){
if(response.body().bytes()!=null){
String result = new String(response.body().bytes(), "UTF-8");
FileUtils.saveFile(FileUtils.Project, result);
}
}
} else {
Log.e(TAG, "获取单个项目详情出异常response == null");
}
} catch (IOException e) {
Log.e(TAG, "获取单个项目详情出异常:" + e.getMessage());
e.printStackTrace();
}
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
Log.e(TAG, "获取单个项目详情出错");
}
});
}
正确的写法
private void getSingProject(String project_inner_id) {
GetSingleProjectRequest getSingleProjectRequest = new GetSingleProjectRequest();
getSingleProjectRequest.setCc(new GetSingleProjectRequest.CcBean(SPUtils.getMyGuid(MyApplication.context)));
getSingleProjectRequest.setPc(new GetSingleProjectRequest.PcBean((project_inner_id)));
Log.e(TAG, "获取单个项目详情" + gson.toJson(getSingleProjectRequest) + SPUtils.getToken(this));
MyApplication.mibeeAPI.getSingleProject2(getSingleProjectRequest, SPUtils.getToken(MyApplication.context)).enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
try {
if (response != null) {
ResponseBody responseBody = response.body();
if (responseBody != null) {
byte[] resultArray = responseBody.bytes();
if (resultArray != null) {
String result = new String(resultArray, "UTF-8");
FileUtils.saveFile(FileUtils.Project, result);
} else {
Log.e(TAG, "获取单个项目详情出异常resultArray == null");
}
} else {
Log.e(TAG, "获取单个项目详情出异常responseBody == null");
}
} else {
Log.e(TAG, "获取单个项目详情出异常response == null");
}
} catch (IOException e) {
Log.e(TAG, "获取单个项目详情出异常:" + e.getMessage());
e.printStackTrace();
}
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
Log.e(TAG, "获取单个项目详情出错");
}
});
}