List of usage examples for org.apache.http.impl.client DefaultHttpClient setCookieStore
public synchronized void setCookieStore(final CookieStore cookieStore)
From source file:com.thoughtmetric.tl.TLLib.java
public static String parseQuoteText(HtmlCleaner cleaner, URL url, TLHandler handler, Context context) throws IOException { DefaultHttpClient httpclient = new DefaultHttpClient(); httpclient.setCookieStore(cookieStore); HttpGet httpGet = new HttpGet(url.toExternalForm()); HttpResponse response = httpclient.execute(httpGet); handler.sendEmptyMessage(PROGRESS_DOWNLOADING); InputStream is = response.getEntity().getContent(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); return parseTextArea(br); }
From source file:com.thoughtmetric.tl.TLLib.java
public static void postMessage(String message, String backurl, String topicId, Context context) throws IOException { DefaultHttpClient httpclient = new DefaultHttpClient(); httpclient.setCookieStore(cookieStore); HttpPost httpost = new HttpPost(POST_URL); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("bericht", message)); nvps.add(new BasicNameValuePair("stage", "1")); nvps.add(new BasicNameValuePair("backurl", backurl)); nvps.add(new BasicNameValuePair("topic_id", topicId)); nvps.add(new BasicNameValuePair("submit_button", "Post")); try {/*from ww w . jav a 2 s . com*/ httpost.setEntity(new UrlEncodedFormEntity(nvps)); HttpResponse response = httpclient.execute(httpost); HttpEntity entity = response.getEntity(); if (entity != null) { entity.consumeContent(); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } }
From source file:com.thoughtmetric.tl.TLLib.java
public static void sendPM(String to, String subject, String message) throws IOException { DefaultHttpClient httpclient = new DefaultHttpClient(); httpclient.setCookieStore(cookieStore); HttpPost httpost = new HttpPost(PM_URL); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("to", to)); nvps.add(new BasicNameValuePair("subject", subject)); nvps.add(new BasicNameValuePair("body", message)); nvps.add(new BasicNameValuePair("view", "Send")); Log.d(TAG, "Sending message"); Log.d(TAG, to);//from w w w . ja v a 2s. c om Log.d(TAG, subject); Log.d(TAG, message); try { httpost.setEntity(new UrlEncodedFormEntity(nvps)); HttpResponse response = httpclient.execute(httpost); HttpEntity entity = response.getEntity(); if (entity != null) { entity.consumeContent(); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } }
From source file:com.thoughtmetric.tl.TLLib.java
public static void editMessage(String message, int topicId, int postId, int currentPage, String token, Context context) throws IOException { DefaultHttpClient httpclient = new DefaultHttpClient(); httpclient.setCookieStore(cookieStore); HttpPost httpost = new HttpPost(EDIT_URL); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("action", "edit")); nvps.add(new BasicNameValuePair("token", token)); nvps.add(new BasicNameValuePair("stage", "1")); nvps.add(new BasicNameValuePair("topic_id", Integer.toString(topicId))); nvps.add(new BasicNameValuePair("post_id", Integer.toString(postId))); nvps.add(new BasicNameValuePair("currentPage", Integer.toString(currentPage))); nvps.add(new BasicNameValuePair("content", message)); nvps.add(new BasicNameValuePair("submit_button", "Update")); try {//w ww . ja va 2s. c o m httpost.setEntity(new UrlEncodedFormEntity(nvps)); HttpResponse response = httpclient.execute(httpost); HttpEntity entity = response.getEntity(); if (entity != null) { entity.consumeContent(); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } }
From source file:com.thoughtmetric.tl.TLLib.java
public static void postNewThread(int forumCode, String subject, String message) throws IOException { DefaultHttpClient httpclient = new DefaultHttpClient(); httpclient.setCookieStore(cookieStore); HttpPost httpost;/* w w w. j a v a 2s . c o m*/ List<NameValuePair> nvps = new ArrayList<NameValuePair>(); if (forumCode == 18) { httpost = new HttpPost(CREATE_NEW_BLOG_POST_URL); nvps.add(new BasicNameValuePair("topic_name", subject)); nvps.add(new BasicNameValuePair("bericht", message)); nvps.add(new BasicNameValuePair("stage", "1")); nvps.add(new BasicNameValuePair("submit", "Post Message")); nvps.add(new BasicNameValuePair("type", "")); } else { httpost = new HttpPost(CREATE_NEW_THREAD_URL); nvps.add(new BasicNameValuePair("topic_name", subject)); nvps.add(new BasicNameValuePair("content", message)); nvps.add(new BasicNameValuePair("submit", "Post Message")); nvps.add(new BasicNameValuePair("type", String.format("%d", forumCode))); } try { httpost.setEntity(new UrlEncodedFormEntity(nvps)); HttpResponse response = httpclient.execute(httpost); HttpEntity entity = response.getEntity(); if (entity != null) { entity.consumeContent(); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } }
From source file:com.thoughtmetric.tl.TLLib.java
public static TagNode TagNodeFromURLEx2(HtmlCleaner cleaner, URL url, Handler handler, Context context, String fullTag, boolean login) throws IOException { handler.sendEmptyMessage(PROGRESS_CONNECTING); DefaultHttpClient httpclient = new DefaultHttpClient(); if (login) {/* w ww.java 2 s.com*/ httpclient.setCookieStore(cookieStore); } HttpGet httpGet = new HttpGet(url.toExternalForm()); HttpResponse response = httpclient.execute(httpGet); handler.sendEmptyMessage(PROGRESS_DOWNLOADING); HttpEntity httpEntity = response.getEntity(); InputStream is = httpEntity.getContent(); return TagNodeFromURLHelper(is, fullTag, handler, context, cleaner); }
From source file:com.thoughtmetric.tl.TLLib.java
public static Object[] tagNodeWithEditText(HtmlCleaner cleaner, URL url, Handler handler, Context context, String fullTag, boolean login) throws IOException { Object[] ret = new Object[2]; handler.sendEmptyMessage(PROGRESS_CONNECTING); DefaultHttpClient httpclient = new DefaultHttpClient(); if (login) {/*ww w . ja v a 2 s .c o m*/ httpclient.setCookieStore(cookieStore); } HttpGet httpGet = new HttpGet(url.toExternalForm()); HttpResponse response = httpclient.execute(httpGet); handler.sendEmptyMessage(PROGRESS_DOWNLOADING); InputStream is = response.getEntity().getContent(); BufferedReader br = new BufferedReader(new InputStreamReader(context.openFileInput(TEMP_FILE_NAME))); ret[0] = TagNodeFromURLHelper(is, fullTag, handler, context, cleaner); ret[1] = parseTextArea(br); return ret; }
From source file:com.thoughtmetric.tl.TLLib.java
public static Object[] parseEditText(HtmlCleaner cleaner, URL url, TLHandler handler, Context context) throws IOException { // Although probably not THE worst hack I've written, this function ranks near the top. // TODO: rework this routine get rid of code duplication. DefaultHttpClient httpclient = new DefaultHttpClient(); httpclient.setCookieStore(cookieStore); HttpGet httpGet = new HttpGet(url.toExternalForm()); HttpResponse response = httpclient.execute(httpGet); handler.sendEmptyMessage(PROGRESS_DOWNLOADING); InputStream is = response.getEntity().getContent(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); FileOutputStream fos = context.openFileOutput(TEMP_FILE_NAME, Context.MODE_PRIVATE); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos)); String line;//from w w w . j a va2 s. com String formStart = "<form action=\"/forum/edit.php"; while ((line = br.readLine()) != null) { if (line.startsWith(formStart)) { Log.d(TAG, line); bw.write(line); break; } } String start = "\t\t<textarea"; String end = "\t\t<p>"; StringBuffer sb = new StringBuffer(); while ((line = br.readLine()) != null) { if (line.startsWith(start)) { bw.write("</form>"); int i = line.lastIndexOf('>'); sb.append(Html.fromHtml(line.substring(i + 1)).toString()); sb.append("\n"); break; } else { bw.write(line); } } while ((line = br.readLine()) != null) { if (line.startsWith(end)) { break; } sb.append(Html.fromHtml(line).toString()); sb.append("\n"); } bw.flush(); bw.close(); if (handler != null) handler.sendEmptyMessage(PROGRESS_PARSING); Object[] ret = new Object[2]; ret[0] = sb.toString(); ret[1] = cleaner.clean(context.openFileInput(TEMP_FILE_NAME)); return ret; }
From source file:org.opensourcetlapp.tl.TLLib.java
public static void logout() throws IOException { DefaultHttpClient httpclient = new DefaultHttpClient(); httpclient.setCookieStore(cookieStore); HttpGet httpGet = new HttpGet(LOGOUT_URL + "?t=" + tokenField); try {/*from w w w . ja v a 2s . c o m*/ httpclient.execute(httpGet); } catch (ClientProtocolException e) { e.printStackTrace(); } loginStatus = false; cookieStore = null; }
From source file:parlare.application.server.controller.ControllerFunctions.java
public static String listCookies(String method, String listCookies) throws IOException { String printHTML = ""; switch (method) { case "javascript": printHTML += "<script>"; printHTML += "function setCookie(name,value,days) { "; printHTML += "var expires = \"\"; if (days) { var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); expires = \"; expires=\" + date.toGMTString(); } "; printHTML += "document.cookie = name + \"=\" + value + expires + \"; path=/\";"; printHTML += "} "; printHTML += "function getCookie(name) { var nameEQ = name + \"=\"; var ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i]; "; printHTML += "while (c.charAt(0) === ' ') { c = c.substring(1, c.length); } if (c.indexOf(nameEQ) === 0) { return c.substring(nameEQ.length, c.length); } } return null; } "; printHTML += "function eraseCookie(name) { setCookie(name, \"\", -1); } "; printHTML += "</script>"; if (listCookies != null) { String[] tokens = listCookies.split(";"); printHTML += "<script>"; for (String token : tokens) { String[] data = token.trim().split("="); if (data.length == 2) { printHTML += " setCookie('" + data[0] + "', '" + data[1] + "', 60);"; }/* w w w. ja va 2 s . co m*/ } printHTML += "</script>"; } break; case "java": DefaultHttpClient httpClient = new DefaultHttpClient(); CookieStore cookieStore = httpClient.getCookieStore(); BasicClientCookie cookie = new BasicClientCookie("HelpMeUniverse", "I need your help my dear universe"); Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DAY_OF_YEAR, 100); cookie.setExpiryDate(calendar.getTime()); cookie.setDomain("localhost"); cookie.setPath("/"); cookieStore.addCookie(cookie); httpClient.setCookieStore(cookieStore); // Prepare a request object HttpGet httpGet = new HttpGet("http://localhost/"); // Execute the request HttpResponse httpResponse = httpClient.execute(httpGet); // Examine the response status System.out.println("Http request response is: " + httpResponse.getStatusLine()); break; } return printHTML; }