代码入下:
/**
* 提交信息
*
* @param s
* 服务器
* @param param
* 提交的数据
* @throws Exception
*/
private void submit(Server s, Map param) throws Exception {
HttpURLConnection conn = (HttpURLConnection) new URL("http://" + s.ip
+ ":" + s.port).openConnection();
String authentication = (new sun.misc.BASE64Encoder())
.encode((s.adminName + ":" + s.adminPassword).getBytes());
conn.setRequestProperty("Authorization", "Basic " + authentication);
if (conn.getResponseCode() != HttpURLConnection.HTTP_OK)
throw new Exception("连接失败!");
conn = (HttpURLConnection) new URL("http", s.ip,
Integer.parseInt(s.port), "/account").openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Authorization", "Basic " + authentication); Iterator it = param.keySet().iterator();
String p = "";
while (it.hasNext()) {
String key = (String) it.next();
p += key + "=" + param.get(key);
if (it.hasNext())
p += "&";
}
OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream());
out.write(p);
out.write("\r\n");
out.flush();
out.close(); BufferedReader br = new BufferedReader(new InputStreamReader(conn
.getInputStream()));
出现的错误:
java.io.IOException: Server returned HTTP response code: 401 for URL: http://127.0.0.1:88/account
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1149)
at tool.proxy.UserManage.submit(UserManage.java:177)
at tool.proxy.UserManage.main(UserManage.java:238) while (br.ready())
System.out.println(br.readLine());
}
/**
* 提交信息
*
* @param s
* 服务器
* @param param
* 提交的数据
* @throws Exception
*/
private void submit(Server s, Map param) throws Exception {
HttpURLConnection conn = (HttpURLConnection) new URL("http://" + s.ip
+ ":" + s.port).openConnection();
String authentication = (new sun.misc.BASE64Encoder())
.encode((s.adminName + ":" + s.adminPassword).getBytes());
conn.setRequestProperty("Authorization", "Basic " + authentication);
if (conn.getResponseCode() != HttpURLConnection.HTTP_OK)
throw new Exception("连接失败!");
conn = (HttpURLConnection) new URL("http", s.ip,
Integer.parseInt(s.port), "/account").openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Authorization", "Basic " + authentication); Iterator it = param.keySet().iterator();
String p = "";
while (it.hasNext()) {
String key = (String) it.next();
p += key + "=" + param.get(key);
if (it.hasNext())
p += "&";
}
OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream());
out.write(p);
out.write("\r\n");
out.flush();
out.close(); BufferedReader br = new BufferedReader(new InputStreamReader(conn
.getInputStream()));
出现的错误:
java.io.IOException: Server returned HTTP response code: 401 for URL: http://127.0.0.1:88/account
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1149)
at tool.proxy.UserManage.submit(UserManage.java:177)
at tool.proxy.UserManage.main(UserManage.java:238) while (br.ready())
System.out.println(br.readLine());
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货