10-30-2008 11:00 AM - edited 10-30-2008 01:16 PM
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.
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.COV
CoverageInfo.isCoverageSufficient(CoverageInfo.COV
Please, help me!
Thanks!
ps:sorry for my english
10-31-2008 03:45 AM
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.
10-31-2008 07:30 AM
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/13
Good luck,
11-03-2008 07:18 AM
Any idea please?
Thks
11-05-2008 02:08 AM
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.
11-05-2008 02:20 AM
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.
11-06-2008 12:21 AM
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.
11-06-2008 06:17 AM
Hi,
Check this link
I use something like this, you should change the headers for your ASP.
Bye
11-10-2008 04:08 AM
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\"\
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.va
http.setRequestProperty("Content-Length",String.va
}
///
////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();
}
}
11-13-2008 09:57 AM
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