67,515
社区成员
发帖
与我相关
我的任务
分享
public static String getPost(String str_url){
try {
URL url = new URL(str_url);
HttpURLConnection urlConn = (HttpURLConnection)url.openConnection();
urlConn.setRequestMethod("POST");
urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
urlConn.setDoInput(true);
urlConn.setDoOutput(true);
urlConn.setUseCaches(false);
urlConn.setInstanceFollowRedirects(true);
urlConn.connect();
DataOutputStream out = new DataOutputStream(urlConn.getOutputStream());
String content = "cbh=陕C11540";
out.writeBytes(content);
out.flush();
out.close();
BufferedReader reader = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
String inputLine = null;
while((inputLine = reader.readLine()) != null){
System.out.println(inputLine);
}
reader.close();
urlConn.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
return "";
}
try {
URL dataUrl = new URL("http://gaj.baoji.gov.cn/gongancar/find.asp");
HttpURLConnection con = (HttpURLConnection) dataUrl
.openConnection();
con.setRequestMethod("POST");
con.setDoOutput(true);
con.setDoInput(true);
OutputStream os = con.getOutputStream();
os.write("cbh=陕C11540".getBytes());
os.flush();
os.close();
InputStream is = con.getInputStream();
byte d[] = new byte[1024];
int size = 0;
while ((size = is.read(d)) != -1)
System.out.println(new String(d, 0, size));
con.disconnect();
} catch (Exception ex) {
ex.printStackTrace();
}
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link href="css.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
.style2 { font-size: 16px;
font-weight: bold;
}
.style4 {font-size: 16px; font-weight: bold; color: #FF0000; }
.style5 {color: #FFFFFF}
.style6 {color: #FF0000}
-->
</style></head>
<body>
<div align="center"><br />
<span class="style2"><br />
<br />
<br />
<span class="style6">尚无您的违章信息!</span></span><span class="style6"><br />
</span>
</div>
</body>
</html>