Back | Reverse | Quick Reply | Post Reply |

Can URLConnection (in Java) Post to PHP file?
Link | by YoGa on 2005-09-21 01:13:06
Can I use URLConnection to post data to php file?...
where I can recive the data back in the php file using
$_POST['test']or$_GET['test']
Is this posiible to be done?

YoGa

Re: Can URLConnection (in Java) Post to PHP file?
Link | by YoGa on 2005-09-23 01:34:57 (edited 2005-09-23 01:37:38)
Yeah,..
I have found the code...(NOT SURE)
Php will recive it by "POST"..

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");}

I will test it...hope to work

YoGa

Re: Can URLConnection (in Java) Post to PHP file?
Link | by YoGa on 2005-09-23 04:45:23
DOESN'T WORK!!!
Although I added DoOutput(true),It didn't work
what's the problem???

YoGa

Back | Reverse | Quick Reply | Post Reply |

Copyright 2000-2025 Gendou | Terms of Use | Page loaded in 0.0006 seconds at 2025-06-26 13:36:19