81,094
社区成员
发帖
与我相关
我的任务
分享
URL url = new URL(".......");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setDoOutput(true); // POST方式
con.setRequestMethod("POST");
OutputStream os = con.getOutputStream(); // 输出流,写数据
os.write("..........".getBytes());
BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream())); // 读取结果
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
URL url = new URL(".......");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setDoOutput(true); // POST方式
con.setRequestMethod("POST");
OutputStream os = con.getOutputStream(); // 输出流,写数据
os.write("..........".getBytes());
BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream())); // 读取结果
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
// 设置连接的基本参数
HttpClient client = new HttpClient();
List authPrefs = new ArrayList(1);
authPrefs.add(AuthPolicy.DIGEST);
client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
client.getState().setCredentials(new AuthScope(null, -1, null),
new UsernamePasswordCredentials("username", "password"));
// 连接
PostMethod method = new PostMethod(connectionURL);
// 发送XML报文
method.setRequestEntity(new StringRequestEntity("要传送的XML内容", "text/html", "utf-8"));
client.executeMethod(method);