get請求(讀取excel裡面的網址和引數)
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import org.apache.http.HttpResponse;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.CellType;
public class POIReadExcelTool { static String url=null; public static void main(String[] args) throws Exception { List<Student> list = readXls(); for(Student stu : list){ System.out.println(stu.getName()); url=stu.getName(); String result=toRunByGET(url); System.out.println(result); } } private static String toRunByGET(String url) throws ClientProtocolException, IOException { String response = null; HttpClient httpclient = null; HttpResponse httpresponse = null; httpclient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); httpresponse = httpclient.execute(httpGet); response = EntityUtils.toString(httpresponse.getEntity()); return response; } public static List<Student> readXls() throws Exception { InputStream is = new FileInputStream("D:/info.xls"); HSSFWorkbook excel = new HSSFWorkbook(is); Student stu = null; List<Student> list = new ArrayList<Student>(); // 迴圈工作表Sheet for (int numSheet = 0; numSheet < excel.getNumberOfSheets(); numSheet++) { HSSFSheet sheet = excel.getSheetAt(numSheet); if (sheet == null) continue; // 迴圈行Row for (int rowNum = 1; rowNum < sheet.getLastRowNum(); rowNum++) { HSSFRow row = sheet.getRow(rowNum); if (row == null) continue; stu = new Student(); HSSFCell cell0 = row.getCell(0); if (cell0 == null) continue; stu.setId((int)cell0.getNumericCellValue()); HSSFCell cell1 = row.getCell(1); if (cell1 == null) continue; stu.setName(cell1.getStringCellValue()); HSSFCell cell2 = row.getCell(2); if (cell2 == null) continue; stu.setAge((int)cell2.getNumericCellValue()); HSSFCell cell3 = row.getCell(3); if (cell3 == null) continue; // stu.setBirth(new SimpleDateFormat("yyyy-mm-dd").parse(cell3.getStringCellValue())); list.add(stu); } } return list; } @SuppressWarnings("unused") private static String getValue(HSSFCell cell) { if (cell.getCellType() == CellType.BOOLEAN) { // 返回布林型別 值 return String.valueOf(cell.getBooleanCellValue()); } else if (cell.getCellType() == CellType.NUMERIC) { //返回數值型別的值 return String.valueOf(cell.getNumericCellValue()); } else { //返回字串型別的值 return cell.getStringCellValue(); } } }