【发布时间】:2017-03-24 01:17:03
【问题描述】:
我目前正在使用改造 1.9,我在使用它时遇到了很多问题,比如我得到改造管道损坏错误和许多东西,所以基本上现在我计划从 1.9 迁移到 2.0,但我很困惑,并且完全沮丧尝试不同的步骤过来吧。如果您能帮助我克服它,我将非常感谢你们。我有我的改造 1.9 代码用于发布并在下面获取请求。请帮助我更改代码的步骤
1> 这是我目前正在使用的唯一 1 个改造依赖项 编译'com.squareup.retrofit:retrofit:1.9.0' 那么我要为依赖项更改什么
2>我的 post and get 改造界面
@POST("/trinkingu/operations.php")
void createNewSeekerProfile( @Query("module") String module,
@Query("action") String action,
@Body SeekerProfileModel body, Callback<Response> callback);
@GET("/synkku/services.php")
void getAlljobPosts(@Query("module") String module,
@Query("action") String action,
@Query("key") String key,
@Query("value") String value, Callback<ArrayList<JobsModel>> response);
3>我的改造助手类
public void addNewSeekerProfile(String module,String action,SeekerProfileModel seekerProfileModel) {
//Here we will handle the http request to insert user to mysql db
//Creating a RestAdapter
System.out.println("##coming here");
RestAdapter adapter = new RestAdapter.Builder()
.setEndpoint(Allconstants.MAIN_URL) //Setting the Root URL
.build(); //Finally building the adapter
//Creating object for our interface
RetroApiInterface api = adapter.create(RetroApiInterface.class);
//Defining the method insertuser of our interface
api.createNewSeekerProfile(
module,
action,
seekerProfileModel,
new Callback<Response>() {
@Override
public void success(Response response, Response response2) {
TypedInput body = response.getBody();
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(body.in()));
StringBuilder out = new StringBuilder();
String newLine = System.getProperty("line.separator");
String line;
while ((line = reader.readLine()) != null) {
out.append(line);
out.append(newLine);
}
// Prints the correct String representation of body.
System.out.println(out);
Toast.makeText(mContext,"result"+out,Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void failure(RetrofitError error) {
Toast.makeText(mContext,"error"+error.toString(),Toast.LENGTH_LONG).show();
error.printStackTrace();
}
}
);
}
这里是获取
public void getAllMyPostedJobs(String inputKey, String inputValue) {
//While the app fetched data we are displaying a progress dialog
//Creating a rest adapter
RestAdapter adapter = new RestAdapter.Builder()
.setEndpoint(Allconstants.MAIN_URL)
.build();
//Creating an object of our api interface
RetroApiInterface api = adapter.create(RetroApiInterface.class);
api.getAlljobPosts(Allconstants.JOBS, Allconstants.ACTION_GET_ALL_MY_POSTEDJOBS, inputKey, inputValue, new Callback<ArrayList<JobsModel>>() {
@Override
public void success(ArrayList<JobsModel> jobsModels, Response response) {
if (mResultCallback != null)
mResultCallback.notifySuccess(jobsModels, response);
System.out.println("###successfull ");
}
@Override
public void failure(RetrofitError error) {
if (mResultCallback != null)
mResultCallback.notifyError(error);
}
});
}
请帮助我现在进行更改以便迁移到 2.0 您的帮助将更加感激 在此先感谢:)
【问题讨论】:
-
我给你所有的代码。一旦我的笔记本电脑可用。直到那时改变dependecy编译'com.squareup.retrofit2:retrofit:2.1.0'
-
需要多少时间? @Divyesh
-
只需 10 分钟,我就有了笔记本电脑。我正在努力。
-
以上问题有解决办法吗?
标签: android android-volley retrofit retrofit2 asynccallback