81,094
社区成员
发帖
与我相关
我的任务
分享
发现我之前用的代码也和你一样的,能不能把地址发一下给我,我用我的试一下:
/**
* 处理页面,得到页面的源码
* @param tempurl
* @return - 页面内容
*/
public static String getHtml(String tempurl, String code) {
try {
URL url = new URL(tempurl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is, code));
String line = "";
StringBuffer resultBuffer = new StringBuffer();
while ((line = br.readLine()) != null) {
resultBuffer.append(line);
}
br.close();
is.close();
conn.disconnect();
return resultBuffer.toString();
} catch (Exception e) {}
return null;
}
public static String cc(String leibie, String num) {
StringBuffer temp = new StringBuffer();
try {
System.out.println(leibie);
System.out.println(num);
String url = "http://www.yb983.com/jiaojing/ser.php";
HttpURLConnection uc = (HttpURLConnection)new URL(url).
openConnection();
uc.setConnectTimeout(10000);
uc.setDoOutput(true);
uc.setRequestMethod("GET");
uc.setUseCaches(false);
DataOutputStream out = new DataOutputStream(uc.getOutputStream());
// 要传的参数
String s = URLEncoder.encode("ra", "GB2312") + "=" +
URLEncoder.encode(leibie, "GB2312");
s += "&" + URLEncoder.encode("keyword", "GB2312") + "=" +
URLEncoder.encode(num, "GB2312");
// DataOutputStream.writeBytes将字符串中的16位的unicode字符以8位的字符形式写道流里面
out.writeBytes(s);
out.flush();
out.close();
InputStream in = new BufferedInputStream(uc.getInputStream());
Reader rd = new InputStreamReader(in, "Gb2312");
int c = 0;
while ((c = rd.read()) != -1) {
temp.append((char) c);
}
System.out.println(temp.toString());
in.close();
} catch (Exception e) {
e.printStackTrace();
}
return temp.toString();
}
public static void main(String[] a){
test.cc("1","吉H");
}