My HttpClient, HttpPost, or HttpGet method is only working once. I can successfully log in an get html from the response the first time, but when I try and log in a second time, the html is blank and I am not even getting a response. What's wrong?
public void parseDoc() {
new Thread(new Runnable() {
@Override
public void run() {
sting.loadData("<p></p>", "text/html", null);
HttpParams params = new BasicHttpParams();
HttpClientParams.setRedirecting(params, true);
httpclient = new DefaultHttpClient();
httppost = new HttpPost(
"https://secure.groupfusion.net/processlogin.php");
String HTML = "";
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(
3);
nameValuePairs
.add(new BasicNameValuePair(
"referral_page",
"/modules/gradebook/ui/gradebook.phtml?type=student_view&jli=t&jli=t&jli=t&jli=t&jli=t&jli=t&printable=FALSE&portrait_or_landscape=portrait"));
nameValuePairs.add(new BasicNameValuePair("currDomain",
"beardenhs.knoxschools.org"));
nameValuePairs
.add(new BasicNameValuePair("username", user));
nameValuePairs
.add(new BasicNameValuePair("password", pass));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HTML = EntityUtils.toString(response.getEntity());
Document doc = Jsoup.parse(HTML);
Element link = doc.select("a").first();
linkHref = link.attr("href");
HttpGet request = new HttpGet();
try {
request.setURI(new URI(linkHref));
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
response = httpclient.execute(request);
InputStream in = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(
new InputStreamReader(in));
StringBuilder str = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
str.append(line);
}
in.close();
HTML = str.toString();
doc = Jsoup.parse(HTML);
Elements divs = doc.getElementsByTag("tbody");
for (Element d : divs) {
if (i == 2) {
finishGrades();
f++;
break;
}
i++;
ggg = d.html();
}
} catch (ClientProtocolException e) {
} catch (IOException e) {
}
}
}).start();
}
OK, I'm not an android person. Have never owned a smartphone. (Never used FB either!) So this is more of a question than an answer. Writing question here is easier than typing in the comments section, especially paragraphing.
Is there any reason you do not close or release the http connection? I am asking because I tend to have to close/release my connections. Except, when I was experimenting with long polling the server. Is that how android programming works?
Is the android a single thread or multi-threaded architecture? What happens when you have two threads trying to open a connection? Will the first thread block the second, especially when the first thread refuses to relinquish the connection?
What happens if you closed or released the connection at the intended end of each request?
What does it mean when you login/logout. Would logging out release/close the connection? Do you specifically logout so that the server closes the connection or is the connection still alive?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With