vendredi 31 octobre 2014

Exception: Already connected In HttpURLConnection


Vote count:

0




I am facing problem in this java function i am trying to post data from my table to server but not able to post as i am getting already connected error


Only the first record is posted



public int myfuction(){

try{

String url = "myurl/page.php";
String urlParameters=null;
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();

//add reuqest header
con.setRequestMethod("POST");
con.setRequestProperty("User-Agent", USER_AGENT);
con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");

Cursor c1 = db.rawQuery("SELECT * FROM temtable ", null);
String id = null;
if (c1 != null ) {
if (c1.moveToFirst()) {
do {
suid = c1.getString(c1.getColumnIndex("puid"));
urlParameters ="text=STAT=1,DEVICEID=10,TERMINALID="+terminal+",USERID="+id;
// Send post request
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();

BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();

while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
//con.disconnect();
Toast.makeText(this, "Send Para-"+urlParameters, Toast.LENGTH_SHORT).show();
pstatus = 1;
}while (c1.moveToNext());
}
}

con.disconnect();

Toast.makeText(this, "Send Success", Toast.LENGTH_SHORT).show();
}
catch(Exception ex)
{
Toast.makeText(this, "Error:"+ ex.getMessage(), Toast.LENGTH_SHORT).show();
}

return 1;
}


This is what i am using please help...



asked 24 secs ago







Exception: Already connected In HttpURLConnection

Aucun commentaire:

Enregistrer un commentaire