Vote count:
0
I usually use $.ajax to send my application data to my WebService, as following:
$.ajax({
type: "POST",
url: server + "/fosco/set",
data: {
"page":"0",
"requestType":"DataSet",
"dataset":createClientJSONObject(),
"params":"[]"
},
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'User-Id' : localStorage.getItem("USER_ID")
},
success: SuccessSetData
Now, I'm using the same WebService for my Java Application, so I wonder the equivalent code to send it as Java Application, using HTTP POST. I started something like following, but don't work:
String url = "http://localhost/service/index.php/fosco/set";
String returnBody = "";
Gson gson = new Gson();
Client fc = new Client();
try {
HttpRequest httpRequest = new HttpRequest();
Hashtable<String, String> params = new Hashtable<String, String>();
params.put("page", "0");
params.put("requestType", "DataSet");
params.put("dataset", gson.toJson(new Client()));
params.put("params", "[]");
returnBody = httpRequest.post(url,
params);
I have debugged my PHP WebService and it show different datasets, it shows JAVA Application dataset as one entire String, but $.ajax as an structured JSON Object. And it doesn't work with JAVA Code.
Question: How to port a $.ajax POST like mine above, as a Java Http POST?
asked 8 mins ago
Java Http POST ajax equivalent for sending structured data JSON
Aucun commentaire:
Enregistrer un commentaire