HTTPURLConneciton的post提交方式

xiaoxiao2025-05-18  28

URL url=new URL(path);

//得到httpurlconnection对象 HttpURLConnection httpURLConnection= (HttpsURLConnection) url.openConnection();

//设置请求方式post httpURLConnection.setRequestMethod(“POST”);

//设置连接时间 httpURLConnection.setConnectTimeout(5000);

//设置http请求数据类型 httpURLConnection.setRequestProperty(“Content-Type”,“application/x-www-form-urlencoded”);

//数据 String data=“mobile=”+name1+"&password="+pwd1;

//告诉服务器我给你提交的数据有多大 httpURLConnection.setRequestProperty(“Content-Length”,data.length()+"");

//要记得指定给服务器写入数据的开关打开 httpURLConnection.setDoInput(true);

//开始往服务器传入数据 httpURLConnection.getOutputStream().write(data.getBytes());

转载请注明原文地址: https://www.6miu.com/read-5030327.html

最新回复(0)