Thanks a ton, but it appears to be having problems posting for some reason. I have all of my post data working and everything, it's saying it's having a problem at this line of HTTPRequest.java:
BufferedReader reader = new BufferedReader(new InputStreamReader((InputStream)URLConnection.getInputStream()));
Not sure why.
I was using this to check for a login success:
request.setURL("http://www.gaiaonline.com/auth/login/");
String login = request.post("", postdata);
if (login.contains("login_success")) {
System.out.println("Logged in successfully!");
}
else {
System.out.println("Login Failed!");
}
But I'm getting an error because the string login is null, it doesn't contain any data because there's something wrong with the actual POST haha. Thanks for updating this though, it's going to be super helpful to me once we can get all of these bugs ironed out.
What's the actual error?
Also do you mind providing me with some post data so I can test with Gaiaonline?
Keep in mind, without specifying certain headers the code will error with java.netSocketException.
For example
HTTPRequest request = new HTTPRequest();
request.setURL("http://www.gaiaonline.com/auth/");
//request.setUserAgent("Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9) Gecko/2008061015 Firefox/3.0");
//request.setAccept("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
// "en-us,en;q=0.5", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
//request.setKeepAlive("300");
//request.setConnection("keep-alive");
//request.setReferer("http://www.gaiaonline.com/auth/login");
//request.setContent("application/x-www-form-urlencoded", "", "en-US");
String postData, thePost;
postData = "username=admin&password=helloworld&sid=1234";
thePost = request.post("", postData);
System.out.println("Post: " + thePost);
Isn't going t

rk. Post will return "null" and a java.netSocketException will be thrown.
However,
HTTPRequest request = new HTTPRequest();
request.setURL("http://www.gaiaonline.com/auth/");
//request.setUserAgent("Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9) Gecko/2008061015 Firefox/3.0");
//request.setAccept("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
// "en-us,en;q=0.5", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
//request.setKeepAlive("300");
//request.setConnection("keep-alive");
//request.setReferer("http://www.gaiaonline.com/auth/login");
request.setContent("application/x-www-form-urlencoded", "", "en-US");
String postData, thePost;
postData = "username=admin&password=helloworld&sid=1234";
thePost = request.post("", postData);
System.out.println("Post: " + thePost);
Will work.
You may not have set the content type.
request.setContent("application/x-www-form-urlencoded", "", "en-US");