Total members 11894 |It is currently Thu Nov 21, 2024 6:59 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





How to open http connection using j2me, Open an http connection ..
Code:
public class Fetcher {

    private static final String BASE_URL = "http://www.amazon.com";
    private static final String QUERY_URL = BASE_URL +
                                "/exec/obidos/search-handle-form/0";

    // Fetches the title, ranking and review count
    // for a book with a given ISBN.
    public static boolean fetch(BookInfo info) throws IOException {

        InputStream is = null;
        OutputStream os = null;
        HttpConnection conn = null;
        int redirects = 0;
        try {
            String isbn = info.getIsbn();
            String query = "index=books&field-keywords=" + isbn + "\r\n";
            String requestMethod = HttpConnection.POST;
            String name = QUERY_URL;

            conn = (HttpConnection)Connector.open(name,
                                                Connector.READ_WRITE);

            // Send the ISBN number to perform the query
            conn.setRequestMethod(requestMethod);
            conn.setRequestProperty("Content-Type",
                        "application/x-www-form-urlencoded");
            os = conn.openOutputStream();
            os.write(query.getBytes());
            os.close();

            // Read the response from the server
            is = conn.openInputStream();
            int code = conn.getResponseCode();

            // Process the returned data (not shown here)
       } finally {
            // Tidy up (code not shown)
       }
    }
}
 

I hop it is useful
You will find more here
http://www.onjava.com/pub/a/onjava/2002/04/17/j2me.html



_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : How to open http connection using j2me
 Using java in http connection     -  
 HTTP POST msg connection close problem     -  
 Get value from HTTP POST VARS     -  
 Send parameters using HTTP GET     -  
 HTTP Server in Java     -  
 http proxy code     -  
 Build distribution applications by remoting(TCP/HTTP)     -  
 Multipart HTTP forms submitter - With Progress Information     -  
 Which open-source CMS is the best?     -  
 Open in a new window help     -  



Topic Tags

Java J2ME
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com