Java
Chilkat2 Java
qa.factura1.com.co Obtain Auth Token
See more HTTP Misc Examples
Demonstrates how to send a JSON POST to get an authenticataion token for qa.factura1.com.coChilkat Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Http;
import com.chilkatsoft.chilkat2.HttpResponse;
import com.chilkatsoft.chilkat2.JsonObject;
public class ChilkatExample {
public static void main(String[] args) {
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Http http = new Http();
// Build the following JSON
// {
// "password": "MY_PASSWORD",
// "username": "MY_USERNAME"
// }
JsonObject json = new JsonObject();
json.setEmitCompact(false);
json.updateString("password", "MY_PASSWORD");
json.updateString("username", "MY_USERNAME");
HttpResponse resp = new HttpResponse();
try {
http.httpJson("POST", "https://qa.factura1.com.co/v2/auth", json, "application/json", resp);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
JsonObject jsonResp = new JsonObject();
jsonResp.setEmitCompact(false);
jsonResp.load(resp.getBodyStr());
System.out.println(jsonResp.emit());
System.out.println("Access token: " + jsonResp.stringOf("token"));
}
}