private void pos() {
new Thread(){
@Override
public void run() {
super.run();
URL url=null;
try {
url=new URL("http://218.244.149.129:9010/api/companylist.php");
HttpURLConnection huc= (HttpURLConnection) url.openConnection();
huc.setReadTimeout(3000);
huc.setRequestMethod("POST");
huc.setDoOutput(true);
huc.connect();
OutputStream os=huc.getOutputStream();
os.write("industryid=98".getBytes());
if (huc.getResponseCode()==200){
InputStream in=huc.getInputStream();
byte[]by=new byte[1024];
int i;
while((i=in.read(by))!=-1){
System.out.println(new String(by,0,i));
}
in.close();
}
os.close();
huc.disconnect();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}.start();
}post请求
最新推荐文章于 2024-05-10 19:35:06 发布
本文介绍了一个使用Java发起HTTP POST请求到指定URL并处理响应的例子。该请求向服务器发送了特定的参数,并展示了如何读取服务器返回的数据。
439

被折叠的 条评论
为什么被折叠?



