public static int sendRequest(String strXml) {
HttpURLConnection c = null;
try {
URL url = new URL(" http://127.0.0.1:8080/xxx/xxx.action");
c = (HttpURLConnection) url.openConnection();
c.setRequestMethod("POST");
c.setDoOutput(true);
c.setDoInput(true);
c.connect();
PrintWriter out = new PrintWriter(new OutputStreamWriter(c.getOutputStream(), "gb2312"));// 发送数据
out.print(strXml);
out.flush();
out.close();
String header;
for (int i = 0; true; i++) {
header = c.getHeaderField(i);
if (header == null)
break;
}
// 接收
int rec = 0;
rec = c.getResponseCode();
System.out.println("提醒种子上传用户状态:" + rec);
if (rec == 200) {
// logger.info("连接成功");
InputStream u = c.getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(u));
String line = "";
while ((line = in.readLine()) != null) {
// logger.info("请求返回:"+line);
}
}
// 接收
c.disconnect();
return rec;
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
HTTP+POST+XML
最新推荐文章于 2022-03-29 15:23:35 发布