Question about posting to https
Hey guys,
I'm trying to do a program that'll post to an https site with some parameters such as username and password using a post action. I have read a bunch of code out there and sort of hacked together something simple I thought would work but I'm definitely doing something wrong. Could anybody tell me if there is something obvious I'm missing with how to get a succesful post action to an https link with parameters on the end via using java code? Right now it compiles perfectly, will run with no errors but I can tell it isn't posting properly to the website so I'm probably missing many somethings that make this not work.
Thanks!
Josh
import java.io.*;
import java.net.*;
import java.util.*;
import javax.net.ssl.*;
import java.net.URL.*;
import java.security.Security;
import java.util.Properties;
import java.io.OutputStreamWriter;
publicclass MyTest2
{
publicstaticvoid main(String[] args)
{
try{
File startFile=new File("test");
String[] theFiles=startFile.list();
// Construct data
String data = URLEncoder.encode("email","UTF-8") +"=" + URLEncoder.encode("myUserEmail","UTF-8");
data +="&" + URLEncoder.encode("password","UTF-8") +"=" + URLEncoder.encode("myPassword","UTF-8");
// Send data
System.out.println(data);
URL url =new URL("https://siteImtrying.com");
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr =new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();
// Get the response
BufferedReader rd =new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) !=null)
{
System.out.println(line);
}
wr.close();
rd.close();
}catch (Exception e){
}
}
}

