Help - Search - Members - Calendar
Full Version: URLConnection for PHP file?Is Possible?
MSFN Forums > Coding, Scripting and Servers > Web Development (HTML, Java, PHP, ASP, XML, etc.)

   
Google Internet Forums Unattended CD/DVD Guide
YoussefGamil
Can I use URLConnection in Java to send parameters to PHP file?
Is it Possible?and does it work?
YoussefGamil
I think I have found it....
It's a code to pass Data to PHP using "POST" method
CODE
URL 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 try
catch(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 try
catch(Exception f){JOptionPane.showMessageDialog(null,"error 2");}
YoussefGamil
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?
Martijn
have you tried an ECHO to output it?
YoussefGamil
No..
But,PRINT instead of ECHO...
(both do the same function!!!)

So,..what is the problem?
Google Internet Forums Unattended CD/DVD Guide
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.