<%@ page import="HTTPClient.HTTPResponse,HTTPClient.HTTPConnection" %>
<%
// calling url is http://127.0.0.1:8080/tsn.jsp?user=youngroman&pass=xxxxx&id=161
// necessary parameters
String user = request.getParameter( "user" );
String pass = request.getParameter( "pass" );
String id = request.getParameter( "id" );
// get a connection to tsn
HTTPConnection con = new HTTPConnection("fantasygames.sportingnews.com");
// set proxy (if necessary)
//con.setProxyServer("proxy", 8080);
// allow auto-cookies
con.setAllowUserInteraction(false);
// login
HTTPResponse resp = con.Get("/crs/home_check_reg.html?username=" + user + "&password=" + pass);
// byte[] data = resp.getData();
// out.println(new String(data));
// get roster
resp = con.Get("/baseball/season1/basic/game/frozen_roster.html?user_id=" + id + "&table_id=2");
// get response
byte[] data = resp.getData();
String site = new String(data); // convert response to string (for following indexOf)
String[] players = new String[8]; // number of players in BasicBaseball
String[] ids = new String[8]; // tsn-ids of players in BasicBaseball
int playerCount = 0;
int pos = site.indexOf("player_id"); // search for string "player_id" at position 0
while(pos != -1) {
int posStart = site.indexOf('>',pos); // start of player-name
int posEnd = site.indexOf('<',posStart); // end of player-name
ids[playerCount] = site.substring(pos + 10, posStart - 1); // player-id
players[playerCount++] = site.substring(posStart + 1, posEnd); // player-name
pos = site.indexOf("player_id",posEnd); // search next
}
%>
<%
// print ids and player-names
for(int i = 0; i < playerCount; i++) {
%>
<%= ids[i] %>
<%= players[i] %>
<% } %>