Exemplo n.º 1
0
  /** Do a Zappos Search and return the result and returns the result */
  public String GetResult(int page) throws IOException {
    String urlStr =
        "http://api.zappos.com/Search?key="
            + zapposKey
            + "&term=&limit=100&sort={\"price\":\"asc\"}";
    if (page != 0) {
      urlStr += "&page=" + page;
    }
    URL url = new URL(urlStr);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();

    if (conn.getResponseCode() != 200) {
      throw new IOException(conn.getResponseMessage());
    }

    // Buffer the result into a string
    BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    StringBuilder sb = new StringBuilder();
    String line;
    while ((line = rd.readLine()) != null) {
      sb.append(line);
    }
    rd.close();

    conn.disconnect();
    return sb.toString();
  }