Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Jun 2006
    Location
    China. Beijing
    Posts
    95

    java.io.IOException: 53-Error in HTTP operation

    Hi,
    I am developping an J2ME application on Nokia SDK 1.0 for java. I need to retrieve map data using goolge static map api.
    I ran the app on my PC, following is my code for retrieving data through http request. Url = "http://maps.google.com/maps/geo?q=beijing&output=csv&key=ABQIAAAA1VYVV9bbajQVMm7FPXPOpRS2trCutCFyfgUBYaUaRBDPahEgTRRx21RsVciHAjRSnyqMYb5VpxtCJA", I have validated the url on ie browser. But when running the line "InputStream is = hc.openInputStream();", an exception threw: java.io.IOException: 53-Error in HTTP operation. From the information in "Diagnostics" windows, there is no "response" for the "request". But curiously, if I change the platform to "Jave(TM) Platform Micro Edition SDK 3.0", the code works well every time. Do you know why? Thanks a lot

    private static byte[] loadHttpFile(String url) throws IOException
    {
    byte[] byteBuffer;
    HttpConnection hc = (HttpConnection) Connector.open(url);
    System.out.println("loadHttpFile:" + url);
    try
    {
    hc.setRequestMethod(HttpConnection.GET);
    InputStream is = hc.openInputStream();
    try
    {
    int len = (int) hc.getLength();
    if (len > 0)
    {
    byteBuffer = new byte[len];
    int done = 0;
    while (done < len)
    {
    done += is.read(byteBuffer, done, len - done);
    }
    }
    else
    {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    byte[] buffer = new byte[512];
    int count;
    while ((count = is.read(buffer)) >= 0)
    {
    bos.write(buffer, 0, count);
    }
    byteBuffer = bos.toByteArray();
    }
    }
    finally
    {
    is.close();
    }
    }
    finally
    {
    hc.close();
    }

    return byteBuffer;
    }

  2. #2
    Nokia Developer Expert
    Join Date
    Aug 2011
    Posts
    555

    Re: java.io.IOException: 53-Error in HTTP operation

    Hi Casper,

    I have tried your code using Nokia SDK 1.0 for Java. This is what I tried:
    Code:
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    
    import javax.microedition.io.Connector;
    import javax.microedition.io.HttpConnection;
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.midlet.MIDletStateChangeException;
    
    
    public class Temp2 extends MIDlet {
    
    	protected void destroyApp(boolean arg0) throws MIDletStateChangeException {}
    	protected void pauseApp() {}
    	protected void startApp() throws MIDletStateChangeException 
    	{
    		byte[] result;
    		try {
    			
    			result=loadHttpFile("http://maps.google.com/maps/geo?q=beijing&output=csv&key=ABQIAAAA1VYVV9bbajQVMm7FPXPOpRS2trCutCFyfgUBYaUaRBDPahEgTRRx21RsVciHAjRSnyqMYb5VpxtCJA");
    			System.out.println(new String(result));
    		} catch (IOException e) {
    			System.out.println("Exception!");
    		}
    		
    	}
    	private static byte[] loadHttpFile(String url) throws IOException 
    	{ 
    		byte[] byteBuffer; 
    		HttpConnection hc = (HttpConnection) Connector.open(url); 
    		System.out.println("loadHttpFile:" + url); 
    		try 
    		{ 
    			hc.setRequestMethod(HttpConnection.GET); 
    			InputStream is = hc.openInputStream(); 
    			try 
    			{ 
    				int len = (int) hc.getLength(); 
    				if (len > 0) 
    				{ 
    					byteBuffer = new byte[len]; 
    					int done = 0; 
    					while (done < len) 
    					{ 
    						done += is.read(byteBuffer, done, len - done); 
    					} 
    				} 
    				else 
    				{ 
    					ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
    					byte[] buffer = new byte[512]; 
    					int count; 
    					while ((count = is.read(buffer)) >= 0) 
    					{ 
    						bos.write(buffer, 0, count); 
    					} 
    					byteBuffer = bos.toByteArray(); 
    				} 
    			} 
    			finally 
    			{ 
    				is.close(); 
    			} 
    		} 
    		finally 
    		{ 
    			hc.close(); 
    		} 
    		
    		return byteBuffer; 
    	} 
    }
    And this is the result I got from the console:
    200,4,39.9042140,116.4074130

    In my case, no exception was thrown and everything worked as expected. In some cases, like when working from within a network that uses proxies to connect to the outside world, you would need to specify a proxy server so that the Emulator can connect to the web. If that's the case, you could ask your system administrator to provide the proxy server settings and then in the Emulator open Tools>Preferences>Networking> enter the proxy settings under HTTP Proxy Server.

  3. #3
    Super Contributor
    Join Date
    Mar 2003
    Posts
    4,110

    Re: java.io.IOException: 53-Error in HTTP operation

    Another option is to use Wireshark and have a look about the HTTP message flow.

Similar Threads

  1. java.io.IOException: Error in HTTP operation
    By varma_111 in forum Mobile Java Networking & Messaging & Security
    Replies: 19
    Last Post: 2011-10-16, 09:27
  2. java.io.IOException: 7-Error in HTTP operation
    By murugacse4 in forum Mobile Java General
    Replies: 1
    Last Post: 2011-08-22, 20:49
  3. IOException java.io.IOException: 40-Error in HTTP operation
    By @RainierLabs in forum Mobile Java General
    Replies: 2
    Last Post: 2011-05-06, 14:23
  4. Getting java.io.IOException: Error in Http operation
    By techendeavour_abhijeet in forum Mobile Java General
    Replies: 3
    Last Post: 2009-05-29, 07:18

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×