StringBuilder sb = new StringBuilder();
sb.append("couponID=1");
sb.append("CouponName=Wendy");
sb.append("couponID=2");
sb.append("CouponName=Wen");
sb.append("couponID=3");
sb.append("CouponName=Danny");
URL Url;
String url="http://example/upload";
try {
Url = new URL(url);
HttpURLConnection conn = (HttpURLConnection) Url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
OutputStreamWriter wr = new OutputStreamWriter(conn
.getOutputStream());
wr.write(sb.toString());
wr.flush();
wr.close();
} catch (Exception e) {
System.out.println(e.toString());
}
使用上面的代码,我正在向服务器发送值,但是服务器如何获取从设备发送的值,并将其添加到表中。