I'm using Google Http Client to code a Post request. Our underlying call is an AJAX post request and the request is successful which return 200 but there is no data added to database. I don't know what wrong with the HTTP Call as the code is design as one HTTP URL call with many function(Add contact, Add organization). How to debug this? Please help me. Thanks.
public void addContact() {
try {
String requestBody = "{'Source': 'Contact', 'MethodName': 'AddContact', 'UserID': '1', 'SalutationID': '1', 'FirstName': 'Peter', "
+ "'LastName': 'Wong', 'JobTitle': 'Software QA', 'PrimaryEmail': 'peterapiit@gmail.com', "
+ "'BusinessPhone': '60163963326', 'CountryID': '104', 'OrganizationID': '1', 'AOIIDs': '2'}";
GenericUrl url = new GenericUrl("https://extranet-uat.who.int/epqs/Main/ServiceProxy");
HttpRequestFactory rf = new NetHttpTransport().createRequestFactory();
HttpRequest request = rf.buildPostRequest(url, ByteArrayContent.fromString("application/json",
requestBody));
request.getHeaders().setContentType("application/json");
HttpResponse response = request.execute();
SoftAssert sAssert = new SoftAssert();
sAssert.assertEquals(response.getStatusCode(), 200);
System.out.println("HTTP Status Code : " + response.getStatusCode());
} catch (IOException ex) {
LogManager.logger.log(Level.INFO, "Exception: " + ex.getMessage());
}
}
The underlying javascript code is available to download from here.