【发布时间】:2016-11-03 01:28:36
【问题描述】:
我有一个要求。我有一个有效的 POST 电话 ("http://localhost:8080/POSTAPI/table/testmaster/create")。我通过邮递员发送了JSON 数据,并将详细信息插入到 MySQL 数据库中。现在我正在尝试通过apache httpcleint 发送json 数据。但是,它无法插入mysql 数据库。
CloseableHttpClient client = HttpClients.createDefault();
HttpPost post = new HttpPost("http://localhost:8080/POSTAPI/table/testmaster/create");
JSONObject testmaster = new JSONObject();
testmaster.put("testRunId", testRunId);
testmaster.put("testClassName", className);
testmaster.put("testMethod", methodName);
testmaster.put("createdBy", "leela");
testmaster.put("createdDate", startDate);
testmaster.put("lastUpdatedBy", "raghu");
testmaster.put("lastUpdatedDate", endDate);
testmaster.put("attribute1", "methodName");
testmaster.put("attribute1Value",methodName );
testmaster.put("attribute2", "result");
testmaster.put("attribute2Value", successResult);
testmaster.put("attribute3", "Test Suite");
testmaster.put("attribute3Value", suiteName);
testmaster.put("attribute4", "test group");
testmaster.put("attribute4Value", TestGroup);
testmaster.put("attribute5", "dataprovider");
testmaster.put("attribute5Value", dataProvider);
StringEntity stringEntity = new StringEntity(testmaster.toString());
post.setEntity(stringEntity);
post.setHeader("Accept", "application/json");
post.setHeader("Content-type", "application/json");
CloseableHttpResponse response = client.execute(post);
System.out.println("Status: "+response.getStatusLine());
这是我尝试过的。如果有人对通过 httpclient 或任何其他替代方法进行后期操作有任何想法,请告诉我。提前致谢。
【问题讨论】:
-
这实际上没有用。
标签: mysql json rest apache-httpclient-4.x