我正在使用Google Http Client编写Post请求。我们的基础调用是AJAX发布请求,请求成功,返回200,但没有数据添加到数据库。我不知道HTTP调用有什么问题,因为代码被设计为一个具有许多功能(添加联系人,添加组织)的HTTP URL调用。如何调试呢?请帮我。谢谢。
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());
}
}
底层的javascript代码可从here下载。