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
Highlighted
New Contributor
Posts: 8
Registered: ‎10-11-2011
My Device: 9700
My Carrier: Maxis

http connection on real device works on wifi but for wap/tcp sometimes give 404 response

Hi, im a new blackberry developer, i have  no problem when using the connection using wifi but when i off my wifi and try to connect using 3g sometimes the data is send but sometimes it dont...what could possibly error in this case?

 

try {
	

String _postData = "";
				OutputStream os;

				//the preferred network is already arranged here
				int[] preferredTransportTypes = {
						TransportInfo.TRANSPORT_TCP_WIFI,
						TransportInfo.TRANSPORT_WAP2,
						TransportInfo.TRANSPORT_TCP_CELLULAR};
				ConnectionFactory factory = new ConnectionFactory();
				factory.setPreferredTransportTypes(preferredTransportTypes);
				factory.setAttemptsLimit(3);
	   	            	factory.setConnectionTimeout(10000);
	            		//factory.setTimeLimit(10000);
				//modify this
       final ConnectionDescriptor connDescriptor = factory.getConnection("http://url here");
	            if(connDescriptor==null){
					UiApplication.getUiApplication().invokeLater(new Runnable()
					{
						public void run()
						{
							Dialog.alert("Invalid Network. Please check your network set up.");
						}
					});
				}else{
					HttpConnection http = (HttpConnection) connDescriptor.getConnection();					
					//https.setRequestMethod(HttpsConnection.POST);
					//byte[] postDataBytes = _postData.getBytes();
					http.setRequestMethod(HttpConnection.POST);
					http.setRequestProperty("User-Agent","Profile/MIDP-2.0 Configuration/CLDC-1.0");
					http.setRequestProperty("Content-Language", "en-US");
					http.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
					//https.setRequestProperty("Content-length", Integer.toString(_postData.length()));
					byte [] postDataBytes = _postData.getBytes("UTF-8");
					
					os = http.openOutputStream();
					os.write(postDataBytes);
					os.flush();
					os.close();
					int state = http.getResponseCode();
					final int state2 = state;
					if(state==HttpConnection.HTTP_OK || state==HttpConnection.HTTP_BAD_GATEWAY){
						UiApplication.getUiApplication().invokeLater(new Runnable()
						{
							public void run()
							{   
								
								//original
								//Dialog.alert("SOS sent. Our customer care personnel will contact you shortly.");
								Dialog.alert("SOS sent. This is the response code : " + state2);
								//Dialog.inform("SOS sent. Our customer care personnel will contact you shortly.");
							}
						});
					} else {
						UiApplication.getUiApplication().invokeLater(new Runnable()
						{
							public void run()
							{                      
								//Dialog.alert("Failed to send SOS .");
								Dialog.alert("Failed to send SOS. Please try again.This is the response code : " + state2);
							}
						});
					}
				}
			} catch(IOException e) {Dialog.inform(e.getMessage());}

 im using blackberry 9700 with os 6

Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: http connection on real device works on wifi but for wap/tcp sometimes give 404 response

You might get a better answer on the Java forum instead of the App World forum.
New Contributor
Posts: 8
Registered: ‎10-11-2011
My Device: 9700
My Carrier: Maxis

Re: http connection on real device works on wifi but for wap/tcp sometimes give 404 response

so should i close this ?