日期:2014-05-20 浏览次数:20888 次
package com.yysoft.stock.price;
import java.io.BufferedInputStream;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
public class GetDataByURL {
public static String cc(String leibie, String num) {
StringBuffer temp = new StringBuffer();
try {
System.out.println(leibie);
System.out.println(num);
String url = "http://qt.gtimg.cn/q=sh600036";
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);