/ Published in: Java
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
//post data to script //be sure to declare private String response = ""; in declaration @Override public void run() { try { BT_debugger.showIt(fragmentName + ": posting to:" + theURL); BT_debugger.showIt(fragmentName + ": data: " + encodedData); urlc.setRequestMethod("POST"); urlc.setDoOutput(true); urlc.setDoInput(true); urlc.setUseCaches(false); urlc.setAllowUserInteraction(false); // urlc.setRequestProperty(HEADER_USER_AGENT, HEADER_USER_AGENT_VALUE); urlc.setRequestProperty("Content-Type","application/x-www-form-urlencoded"); // perform POST operation dataout.writeBytes(encodedData); // write html to System.out for debug StringBuilder sb = new StringBuilder(); BT_debugger.showIt(fragmentName + ": the response="); while ((line = in.readLine()) != null) { BT_debugger.showIt(line); sb.append(line + "\n"); //return response; } response = sb.toString(); in.close(); //return response; response = e.toString(); //return e.toString(); response = e.toString(); //return e.toString(); } finally { if (out != null) { try { out.close(); //return response; response = e.toString(); //return e.toString(); } } if (in != null) { try { in.close(); //e.printStackTrace(); response = e.toString(); } } } } }); performPostThread.start(); try { performPostThread.join(); e.printStackTrace(); } return response; }