我正在尝试将 post 方法中的 URL 中的两个参数传递给 http 连接,但没有获得任何成功,任何人都可以帮我解决代码是
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
// add request header
con.setRequestMethod("POST");
con.setDoOutput(true);
con.setDoInput(true);
con.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
JsonObject requestData = new JsonObject();
requestData.addProperty("email", "nitin@eye-watch.in");
requestData.addProperty("name", "nitin malik");
requestData.addProperty("phone_no", "9540825737");
File fileToUpload = new File("/home/nitin/Desktop/clientdcs.jpg");
String urlParameters = "form=" + requestData.toString() + "&file=" + fileToUpload;
// Send post request
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();