YoussefGamil Posted September 21, 2005 Posted September 21, 2005 Can I use URLConnection in Java to send parameters to PHP file?Is it Possible?and does it work?
YoussefGamil Posted September 23, 2005 Author Posted September 23, 2005 I think I have found it....It's a code to pass Data to PHP using "POST" methodURL myURL=null;URLConnection urlConn=null;DataOutputStream printout=null;DataInputStream input=null;try{ url=new URL(getCodeBase(),"Picks/"+"writeToFile.php"); }catch(Exception easidghih){} try{ urlConn=myURL.openConnection(); }catch(Exception w){JOptionPane.showMessageDialog(null,"openConnection() error");}try{ urlConn.setDoInput(true); urlConn.setUseCaches(false); }//end of trycatch(Exception a){JOptionPane.showMessageDialog(null,"Exception here");}try{ printout=new DataOutputStream(urlConn.getOutputStream()); String content="File="+URLEncoder.encode(username+".txt","UTF-8")+"&text="+URLEncoder.encode(Long.toString(number),"UTF-8"); printout.writeBytes(content); printout.flush(); printout.close(); }//end of trycatch(Exception f){JOptionPane.showMessageDialog(null,"error 2");}
YoussefGamil Posted September 23, 2005 Author Posted September 23, 2005 DOESN'T WORK!!!Although I added DoOutput(true),It didn't work!!Is there a way to make it work??or..Is there another way to make the same function?
YoussefGamil Posted September 29, 2005 Author Posted September 29, 2005 No..But,PRINT instead of ECHO...(both do the same function!!!)So,..what is the problem?
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now