2 回答
TA贡献1805条经验 获得超9个赞
您应该将 json 数据写入请求正文。为此,您可以使用OutputStreamWriter类写入如下输出流HttpURLConnection:
String ticketCheck = "{ \"function\":\"Check\",\"teamId\":IC106-2,\"teamKey\":1b3741ccf6d9ec5245055370125d901e,\"requestId\":1,\"firstName\":\"" + fname + "\" ,\"lastName\":\""+lastName+"\",\"ticketNumber\":\"\"" + ticketnummer + "\"}";
HttpURLConnection con = (HttpURLConnection) object.openConnection();
con.setDoOutput(true);
con.setDoInput(true);
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("Accept", "application/json");
con.setRequestMethod("POST");
OutputStreamWriter writer = new OutputStreamWriter(con.getOutputStream());
writer.write(ticketCheck);
//this line closes the outputstream and actually makes the http request is sent
writer.flush();
TA贡献1805条经验 获得超10个赞
解决了。简单的报价错字。“错误请求”意味着语法错误,我忘记在函数旁边添加 \" 。
String ticketCheck = "{\"function\":\"Check\",\"teamId\":\"IC106-2\",\"teamKey\":\"1b3741ccf6d9ec5245055370125d901e\",\"requestId\":\""+REQ_ID+"\",\"firstName\":\""+fname+"\",\"lastName\":\""+lastName+"\",\"ticketNumber\":\""+ticketNummer+"\"}";
上面正确的json
添加回答
举报