Copy tan
directory to your Java project.
Platform | Version |
---|---|
Java | 7+ |
Android | 7.0+ |
import tan.Tanserver;
import java.io.IOException;
/* Initialize connection information. */
Tanserver tan = new Tanserver("tanserver.org", 2579);
/* Get JSON string from the server. */
tan.getJSON("api", "{}", new Tanserver.Callback() {
@Override
public void onSuccess(String jsonString) {
System.out.println(jsonString);
}
@Override
public void onFailure(IOException err) {
/* An error has occurred, notify the user of network failure. */
System.out.println("ERROR! " + err.getMessage());
}
});
Declaration | void getJSON(String userApi, String jsonString, Callback callback) |
---|---|
Description | Get JSON string from the server. |
Param userApi |
API provided by the server. |
Param jsonString |
The JSON string that will be sent to the server. |
Param callback |
Needs to implement void onSuccess(String jsonString) and void onFailure(IOException err) . When the request is successful, onSuccess() will be called, otherwise onFailure() will be called. |
Note | Android must add <uses-permission android:name="android.permission.INTERNET"/> in AndroidManifest.xml |
-
The client is offline or the server is not started.
-
SSL handshake failed.
-
API does not exist.
-
jsonString
is an invalid JSON string. -
jsonString
is too large and exceedsclient_max_body_size
.