g.shweta5 0 Report post Posted April 19, 2007 (edited) We are developing a chat application for Rel. CDMA phone and for this we are trying to send an receive data but its not working when we are using POST method. Can any one explain me how to write code it for server n client side, bcoz we r written server for the same. public String readData(String url) { if(url==null) return null; String data=null; try { if (!url.startsWith("http://") && !url.startsWith("https://")) { url = "http://" + url; } } catch (Exception ex) { return null; } try { buffer=new StringBuffer(); conn = (HttpConnection)Connector.open(url); //// conn.setRequestMethod(HttpConnection.GET); conn.setRequestMethod(HttpConnection.POST); //// conn.setRequestProperty("If-Modified-Since","29 Oct 1999 19:43:31 GMT"); conn.setRequestProperty("User-Agent","Profile/MIDP-1.0 Configuration/CLDC-1.0"); conn.setRequestProperty("Content-Language", "en-US"); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); //post DataOutputStream os = conn.openDataOutputStream(); os.writeInt(20); os.writeInt(1); os.writeInt(12); os.writeUTF("919820301007"); os.writeUTF("919322078009"); // os.write(postData.getBytes()); ////// os.flush(); // Optional, openInputStream will flush //-post int responseCode=conn.getResponseCode(); System.out.println("responseCode="+responseCode); if(responseCode== HttpConnection.HTTP_OK && ! canceled) { int len = (int) conn.getLength(); is = conn.openInputStream(); if (len == -1) { // unknown length? // read until .read() returns -1 int ch; while((ch=is.read())!= -1) { buffer.append((char) ch); } } else { // known length for (int i=0; i <len; i++)//="i++)" { //// System.out.println("&&&&&&&&&& : "+ is.read()); buffer.append((char) is.read()); } ////// int ch; ////// while((ch=is.read())!= -1) ////// { ////// System.out.println("&&&&&&&&&& : "+(char) ch); ////// buffer.append((char) ch); ////// } } //// is.close(); data=buffer.toString(); } else { } } catch(Exception ex) { //// System.out.println("Exception=="+ex); ex.printStackTrace(); return null; } finally { try{ if(is!=null){ is.close(); is=null; } }catch (Exception ex){} try{ if(conn!=null){ conn.close(); conn=null; } }catch (Exception ex){} } System.out.println("returning data=="+data); if(!canceled) return data; else return null; } Edited April 23, 2007 by g.shweta5 Share this post Link to post Share on other sites
linuxguy 0 Report post Posted April 26, 2007 firstly, comment ur code properly. secondly, remove the phone numbers, they can be misused. next describe your problem in DETAIL. "Doesnt work" isn't a valid description Share this post Link to post Share on other sites