Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
mlera
Posts: 9
Registered: ‎10-24-2008
My Device: Not Specified

HttpDemo and HttpConnection problem

[ Edited ]

Hi all,

 

Im developing a file explorer application with a transfer file option, to transfer files to my server (using HTTP Post headers and .net Webservice using ksoap), in simulator it works great! but on my blackberry doesnt so i try HttpDemo Sample (to test connection issues) but when i test it on my device have problems. I have been reading a lots of topics about HttpConnection, Socket connection, also read Howtos in the BB KB, but still with the problem.

 

First try the app without changes, and the error was "Java.io.IOException:could not open tunnel - failed "

Then change the url to "https://www.blackberry.com/go/mobile/samplehttps.shtml;deviceside=true;apn=wap.gprs.unifon.com.ar;t..."

to force my device to use a direct TCP connection and the error change to "Java.io.IOException: Bad DNS Address".

 

Then change TLS to "Allow HTTPS redirect" in Options > Security > TLS (solution used in other forum) but still with errors. Also tried with deviceside=false, and the error was "invalid URL parameter", so i realize that my device dont use MDS/BES service, and uses BIS or WAP (Is there a way to find out what type of connection i am using?).

In Options > Advanced > TCP fields are blank, but i override this values passing in the URL above.

 

Maybe is it a problem with my carrier (Movistar/Argentina)? (APN settings are OK)

Also try installing an app (www.itookthisonmyphone.com) with the same functionality as mine, and its works, so im losing something here.

 

Using: 

JDE 4.2

device Blackberry 8100 perl

 

Also try:

CoverageInfo.getCoverageStatus() >> 7

CoverageInfo.isCoverageSufficient(CoverageInfo.COVERAGE_CARRIER)) >> TRUE
CoverageInfo.isCoverageSufficient(CoverageInfo.COVERAGE_MDS)) >> TRUE

 

Please, help me!

Thanks!

 

ps:sorry for my english

 

 

 

 

 

Message Edited by mlera on 10-30-2008 11:55 AM
Message Edited by mlera on 10-30-2008 01:16 PM
Please use plain text.
New Developer
amolsarmalkar
Posts: 13
Registered: ‎10-25-2008
My Device: Not Specified

Re: HttpDemo and HttpConnection problem

Hi mlera, I am also trying to post a file to Asp Server thorugh BlackBerry.

I am glad to know that you got success in working the sample HttpDemo work on simulator.

 

CAn u please tell me whether did any additional settings on Simulator for making HttpDemo sample work?

 

I am also trying the same on my side And will let you know if I get any succes in the same.

Please use plain text.
New Developer
mlera
Posts: 9
Registered: ‎10-24-2008
My Device: Not Specified

Re: HttpDemo and HttpConnection problem

Hi amolsarmalkar,

For running httpdemo in simulator you have to open MDS service, you can configure this in JDE:

Preferences > Simulator > Check option Launch MDS with simulator

Preferences > MDS Simulator > Set the path of your MDS directory

 

Also you can check MDS configuration in this thread:

http://www.blackberryforums.com/developer-forum/133143-http-connection-problem.html

 

Good luck,

 

Please use plain text.
New Developer
mlera
Posts: 9
Registered: ‎10-24-2008
My Device: Not Specified

Re: HttpDemo and HttpConnection problem

Any idea please?

Thks

Please use plain text.
New Developer
amolsarmalkar
Posts: 13
Registered: ‎10-25-2008
My Device: Not Specified

Re: HttpDemo and HttpConnection problem

I am able to post text data thr Http post on device simulator by starting MDS simulator.

However for sending whole file to asp page we need to have some  additional code inside that ASP page to accept the file.

We have written such a page and we are able to post a file through c#.

Now I am trying the same to do it on Blackberry...But one thing I found that java and c# has many similarities.

Please use plain text.
New Developer
amolsarmalkar
Posts: 13
Registered: ‎10-25-2008
My Device: Not Specified

Re: HttpDemo and HttpConnection problem

hi mlera,

Any idea how to  configure headers for posting a file through Http .

Any link relaed to BlackBerry forum /docs will help me.

It is really nice to hear  that you are succesful in posting file through simulator.

Please use plain text.
New Developer
amolsarmalkar
Posts: 13
Registered: ‎10-25-2008
My Device: Not Specified

Re: HttpDemo and HttpConnection problem

Hi all,

 

Can anyone please tell me whether any information about http headers  and encoding format for data is given for BlackBerry for posting a file to an ASP page.

I found this statement in a pdf for JDE guide

byte[] encoded = Base64OutputStream.encode(login.getBytes(), 0, login.length(), false, false);

 

I am able to post Text data .But for posting a whole file some more information regarding HTTP headers and exact encoding format is required which I want.

 

 

        

Please use plain text.
New Developer
mlera
Posts: 9
Registered: ‎10-24-2008
My Device: Not Specified

Re: HttpDemo and HttpConnection problem

Hi,

 

Check this link

 

https://developer.sonyericsson.com/site/global/techsupport/tipstrickscode/java/p_post_javafile_webse...

 

I use something like this, you should change the headers for your ASP.

Bye

Please use plain text.
New Developer
amolsarmalkar
Posts: 13
Registered: ‎10-25-2008
My Device: Not Specified

Re: HttpDemo and HttpConnection problem

hi mlera,

thanks for the help given

 

 

I am trying with this code

 

But not able to post the file at server.In response from server I m getting some junc characters .

There is a mistake in headers in the folowing code.Can u please tell me where I am going wrong / how to get correct response.

 

http = (HttpConnection) Connector.open(url);
               
        String boundary ="multipart/form-data; boundary="+ "-----------------------------4664151417711" ;   
     
     
     //   http.setRequestProperty("Content-Type",boundary );
        http.setRequestMethod(HttpConnection.POST); 
        http.setRequestProperty("User-Agent", "BlackBerry/3.2.1");
        http.setRequestProperty("Content-Language", "en-US");
        http.setRequestProperty("Connection", "close");
        //form header here c#
        String boundary1 = "\r\n--" + boundary + "\r\n";
        byte boundarybytes[] = boundary1.getBytes();
 
            // Get the header for the file upload
                        String header = "Content-Disposition: form-data; name=\"uploadedfile\";filename=\"Blackberry.jpg\"\r\n  Content-Type: image/jpeg\r\n\r\n";

byte headerbytes[] = header.getBytes();
 
           FileConnection fconnFrom = null;
           int fileSize = 0;
           fconnFrom =(FileConnection) Connector.open("file:///SDCard/Blackberry.jpg");         
           if (fconnFrom.exists())
            {
               // fconnFrom.setReadable(true);
           // fconnFrom.setWritable(true);
            fileSize = (int) fconnFrom.fileSize();
            // http.setRequestProperty("Content-Length",String.valueOf(2+ fileSize +headerbytes.length + 2*boundarybytes.length));
             http.setRequestProperty("Content-Length",String.valueOf( fileSize +headerbytes.length + boundarybytes.length));
            }
               
           ///
           
      
 
                 ////form header here
       oStrm = http.openOutputStream() ;   
     
      // Write the header including the filename.
      oStrm.write(boundarybytes);
       oStrm.write(headerbytes);
      
       //
        byte imgData[] = new byte[fileSize];
        DataInputStream dataIn = fconnFrom.openDataInputStream();      
        int writtenBytes = 0;       
        dataIn.read(imgData, 0, fileSize);
       
        ///added on 10/11/2008
        int index = 0;
        int size = 1024;
        do
        {
           // System.out.println("write:" + index);
            if((index+size) > imgData.length)
            {
                size = imgData.length - index;
            }
            oStrm.write(imgData, index, size);
            index+=size;
        }while(index<imgData.length);        
                
        dataIn.close();       
         oStrm.write(boundarybytes);     
       fconnFrom.close();


     
       iStrm = http.openInputStream();      
             
    }
            catch ( Exception e )
            {
            //  System.out.println("IO error trying to read your input line!");
            //  e.printStackTrace();
            System.out.println(e);
            System.exit(1);
            }
            finally
            {
            // Clean up
            //if (iStrm != null)
                //iStrm.close();
            //if (oStrm != null)
            //  oStrm.close();       
            //if (http != null)
            //  http.close();
            }
 
        
     }
   
 

  

Please use plain text.
Administrator
MSohm
Posts: 14,241
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: HttpDemo and HttpConnection problem

The user agent should match the BlackBerry model and handheld software version you are using.  Otherwise, you data could be corrupted.  Please see this link for more information.

 

Support - HTTP transmits incorrectly when User-Agent includes "BlackBerry"
Article Number: DB-00600

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800563/Support...

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.