Found! I forgot to open a stream connection
requestOut = connection.openOutputStream();
and I introduced ByteArrayOutpuStream , which helped me finally display the input stream. I also changed the way parameters were sent and used the URLEncodedPostData type URLEncodedPostData . Since the server interpreted my previous request as GET instead of POST. And all I have to do now is to parse the information.
try{ connection = (HttpConnection)Connector.open("http://someurl.xml",Connector.READ_WRITE); URLEncodedPostData postData = new URLEncodedPostData(URLEncodedPostData.DEFAULT_CHARSET, false); postData.append("username", "loginapi"); postData.append("password", "myapilogin"); postData.append("term", word); connection.setRequestMethod(HttpConnection.POST); connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded"); connection.setRequestProperty("User-Agent","Profile/MIDP-2.0 Configuration/CLDC-1.0"); requestOut = connection.openOutputStream(); requestOut.write(postData.getBytes()); String contentType = connection.getHeaderField("Content-type"); detailIn = connection.openInputStream(); int length = (int) connection.getLength(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); if(length > 0){ byte info[] = new byte[length]; int bytesRead = detailIn.read(info); while(bytesRead > 0) { baos.write(info, 0, bytesRead); bytesRead = detailIn.read(info); } baos.close(); connection.close(); requestSuceeded(baos.toByteArray(), contentType); detailIn.read(info); } else { System.out.println("Negative array size"); } requestOut.close(); detailIn.close(); connection.close(); }
PS. I posted the above code to help anyone with the same problem.
SFC. I also used the Kalai format , and it helped wonderfully.
source share