I'm new to Android development and try to use OkHttp making a POST request showing the data upon my Android APP, I referred to several examples then assemble them to the classes beneath, yet it didn't acquire any data, I expect to acquire the data from the OkHttp class, afterward send it to the API class, may I ask where it gone wrong and how to adjust it?
the OkHttp class:
public static class OkHttpPost {
OkHttpClient client = new OkHttpClient();
RequestBody requestBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.build();
@TargetApi(Build.VERSION_CODES.KITKAT)
String run(String url) throws IOException {
Request request = new Request.Builder()
.method("POST", requestBody.create(null, new byte[0]))
.url("124.173.120.222")
.post( requestBody )
.build();
try (Response response = client.newCall(request).execute()) {
return response.body().string();
}
}
public static void main(String[] args) throws IOException {
OkHttpPost Post = new OkHttpPost();
String response = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
response = Post.run("124.173.120.222");
}
System.out.println(response);
}}
API class:
ConnectAPI.A110(context, Scode, Manual, new ZooCallback(){
@Override
public void onSuccess(JSONObject response){
super.onSuccess(response);
try{
new OkHttpPost();
open.setText(response.getString("Open"));
high.setText(response.getString("High"));
low.setText(response.getString("Low"));
}
catch(JSONException e){
Log.d("A110 gone wrong", e.getMessage());
}
}
public void onFail(String title, String errorMessage){
super.onFail(title, errorMessage);
Log.d(TAG, errorMessage);
}
});