Definately. Here's a very basic one I wrote to test just that a while ago.

import javax.servlet.*;
import javax.servlet.http.*;
import java.net.*;
import java.io.*;

public class URLServlet extends HttpServlet {
    public void doGet(HttpServletRequest req, HttpServletResponse res)
        throws ServletException, IOException {
        
        // set the HTML 'out'
        PrintWriter htmlOut = res.getWriter();

        // Build the query String
        String query = "UserName=jonbrown3&Password=fencing&"+
                       "PasswordConfirm=fencing&Email=testing"+
                       "5%40robot6.com&action=RegSubmit&Submit"+
                       "=Submit+Registration";

        // Create a URL and open a connection
        URL url = new URL("put your cgi-url here");
        HttpURLConnection conn = (HttpURLConnection)url.openConnection();

        // Make the Connection writeable        
        conn.setDoOutput(true);
        PrintWriter out = new PrintWriter(conn.getOutputStream());

        // Print the query string to the output stream
        out.println(query);

        // perform the connect, and close the output stream
        conn.connect();
        out.close();
        
        // read the response from the cgi script
        BufferedReader in = new BufferedReader(new
            InputStreamReader((InputStream)conn.getContent()));
            
        // output the input stream
        String inputLine = null;        
        while((inputLine = in.readLine()) != null) {
            System.out.println(inputLine);
            htmlOut.println(inputLine);
        }

    }

}

At 07:02 PM 8/1/00 -0300, Guilherme Ceschiatti wrote:
>HI!
>
>I need to make a servlet (or JSP page) to get an external page using the
>method POST. Is it possible with the URLConnection class? 
>
>Thanks.
>Guilherme Ceschiatti
>
>
/**     
 * @author: Lorin Kobashigawa-Bates <[EMAIL PROTECTED]>
 * @title:  CodeMonkey / COO - Robot6 Inc. 
 * @phone:  415.345.8872
 * @addr:   1177 Polk St. San Francisco, CA 94109
 */

Reply via email to