rt

解决方案 »

  1.   

    1.简单的get请求
    URL u = new URL("http://xxxx/aaa"); 
    InputStream is = u.openStream();2.post请求
    String data = URLEncoder.encode("key1", "UTF-8") + "=" + URLEncoder.encode("value1", "UTF-8");
    data += "&" + URLEncoder.encode("key2", "UTF-8") + "=" + URLEncoder.encode("value2", "UTF-8");
        
    // Send data
    URL url = new URL("http://xxx/test.jsp");
    URLConnection conn = url.openConnection();
    conn.setDoOutput(true);
    OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
    wr.write(data);
    wr.flush();
        
    // Get the response
    BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    String line;
    while ((line = rd.readLine()) != null) {
                // Process line...
    }
    wr.close();
    rd.close();也可以使用 Jakarta Commons HttpClient,使用更简单