So my goal is to enter the forum using httpclient and then post the response to the thread on this forum. I log in to the system in order, but then when I go to the message in the stream, it says that I have not logged in. Any ideas? I tried to create httpClient using cookies, but then I looked at them after I logged in and there was nothing. So I tried using the same httpclient for both calls, but still did not work.
String username, password, threadNum, bumpMessage, bumpTimer;
HttpClient http;
public void login() throws ClientProtocolException, IOException, NoSuchAlgorithmException
{
this.http = HttpClients.createDefault();
HttpPost httppost = new HttpPost("http://www.sythe.org/login.php?do=login");
List<NameValuePair> params = new ArrayList<NameValuePair>(2);
params.add(new BasicNameValuePair("do", "login"));
params.add(new BasicNameValuePair("url", ""));
params.add(new BasicNameValuePair("vb_login_md5password", this.password));
params.add(new BasicNameValuePair("vb_login_md5password_utf", this.password));
params.add(new BasicNameValuePair("s", ""));
params.add(new BasicNameValuePair("vb_login_username", this.username));
params.add(new BasicNameValuePair("vb_login_password", ""));
httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
HttpResponse response = http.execute(httppost);
HttpEntity entity = response.getEntity();
}
public void bump() throws ClientProtocolException, IOException
{
HttpPost httppost = new HttpPost("http://www.sythe.org/newreply.php?do=postreply&t=" + this.threadNum);
List<NameValuePair> params = new ArrayList<NameValuePair>(2);
params.add(new BasicNameValuePair("title", ""));
params.add(new BasicNameValuePair("message", this.bumpMessage));
params.add(new BasicNameValuePair("wysiwyg", "0"));
params.add(new BasicNameValuePair("iconid", "0"));
params.add(new BasicNameValuePair("s", ""));
params.add(new BasicNameValuePair("posthash", ""));
params.add(new BasicNameValuePair("poststarttime", ""));
params.add(new BasicNameValuePair("loggedinuser", ""));
params.add(new BasicNameValuePair("multiquoteempty", ""));
params.add(new BasicNameValuePair("sbutton", "Submit Reply"));
params.add(new BasicNameValuePair("signature", "1"));
params.add(new BasicNameValuePair("parseurl", "1"));
params.add(new BasicNameValuePair("emailupdate", "9999"));
httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
HttpResponse response = this.http.execute(httppost);
HttpEntity entity = response.getEntity();
PrintWriter writer = new PrintWriter("filename.html","UTF-8");
if (entity != null) {
InputStream instream = entity.getContent();
String line;
BufferedReader br = null;
try {
br = new BufferedReader(new InputStreamReader(instream));
while ((line = br.readLine()) != null) {
writer.println(line);
}
} finally {
instream.close();
}
}
writer.close();
}
}
Edit: I got it in python!
jar = cookielib.FileCookieJar("cookies")
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar))
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
def login():
logindata = urllib.urlencode({'do' : 'login',
'url':'',
'vb_login_md5password' : password,
'vb_login_md5password_utf' : password,
's' : '',
'vb_login_username': username,
'vb_login_password': '' })
response = opener.open("http://www.sythe.org/login.php?do=login", logindata)
def bumpThread():
if(username == "Not set" or password == "Not set"):
print "Please setup password!"
return
if(threadNum == 0 or message == "Not set" or bumpTime == 0):
print threadNum
print message
print "Please setup thread!"
return
logindata = urllib.urlencode({'title' : 'The Thread',
'message' : message,
'wysiwyg' : '0',
'iconid' : '0',
's' : '',
'do' : 'postreply',
't' : threadNum,
'p' : '',
'posthash' : '',
'poststarttime' : '',
'loggedinuser' : '',
'multiquoteempty' : '',
'sbutton' : 'Submit Reply',
'signature' : '1',
'parseurl' : '1',
'emailupdate' : '9999' })
thread = opener.open("http://www.sythe.org/newreply.php?do=postreply&t=" + str(threadNum),logindata)