@Override protected String doInBackground(String... url) { if (allPhoneContacts != null) { allPhoneContacts.clear(); } if (syncedContacts != null) { syncedContacts.clear(); } String resp = ""; Header[] responseHeaders = null; HttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, TIMEOUT_MILLSEC); HttpGet request = new HttpGet(url[0]); MyHttpClient Client = LogonClass.Client; Client.putContext(context); try { request.setHeader("syncstatus", "True"); HttpResponse response = Client.execute(request); resp = EntityUtils.toString(response.getEntity()); responseHeaders = response.getAllHeaders(); } catch (Exception e) { resp = "none is righteous"; } Log.v(TAG, "response is " + resp); return resp; }
private void sendProposal( String capabilities2, String rate2, String email2, String subject2, String message2) { // Log.d("TAG",key); MyHttpClient client = new MyHttpClient(Proposal.this); HttpPost post = new HttpPost("https://helium.staffittome.com/apis/create_proposal"); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); nameValuePairs.add(new BasicNameValuePair("session_key", staffkey)); nameValuePairs.add(new BasicNameValuePair("capability_id", capabilities2)); nameValuePairs.add(new BasicNameValuePair("payment_method", "1")); nameValuePairs.add(new BasicNameValuePair("rate", rate2)); nameValuePairs.add(new BasicNameValuePair("email", email2)); nameValuePairs.add(new BasicNameValuePair("subject", subject2)); nameValuePairs.add(new BasicNameValuePair("message", message2)); try { post.setEntity(new UrlEncodedFormEntity(nameValuePairs)); ResponseHandler<String> responseHandler = new BasicResponseHandler(); String responseBody = client.execute(post, responseHandler); Log.d("TAG", "TEST RESULTS FROM HTTPS SEND PROPOSAL IS: " + responseBody); Toast.makeText(getApplicationContext(), responseBody, 0).show(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } }
public static void main(String[] args) throws IOException, ParserConfigurationException, SAXException, SQLException { Setting.Loadsetting(); String doi = "10.1126/science.1211177"; MyHttpClient myHttpClient = new MyHttpClient(); // System.out.println(myHttpClient.get_pmid("10.1101/gr.121392.111")); // String pmid = "21940856"; // System.out.println(myHttpClient.get_doi(pmid)); // System.out.println(myHttpClient.get_sample_attributes("SRS173976")); String url = "http://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?mode=Info&id=90"; System.out.println("*" + myHttpClient.getGenbank_name(url) + "*"); }
@Override protected String doInBackground(String... url) { String resp = ""; String username = ""; HttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, TIMEOUT_MILLSEC); HttpConnectionParams.setSoTimeout(httpParams, TIMEOUT_MILLSEC); HttpPost request = new HttpPost(url[0]); MultipartEntityBuilder MEB = MultipartEntityBuilder.create(); Charset chars = Charset.forName("UTF-8"); MEB.setCharset(chars); MEB.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); try { JSONArray contactsArray = new JSONArray(); for (int i = 0; i < selectedItemList.size(); i++) { JSONObject contactObj = new JSONObject(); File getFile = new File(context.getFilesDir().getPath() + "/", selectedItemList.get(i)); FileBody fb = new FileBody(getFile); contactObj.put("contact", selectedItemList.get(i)); contactsArray.put(contactObj); MEB.addPart(selectedItemList.get(i), fb); fb = null; } selectedItemList.clear(); byte[] contacts = contactsArray.toString().getBytes(); MEB.addBinaryBody("contactsArray", contacts); contactsArray = null; HttpEntity ent = MEB.build(); request.setEntity(ent); // request.setEntity(new ByteArrayEntity(file.toString().getBytes("UTF8"))); MyHttpClient Client = LogonClass.Client; Client.putContext(context); HttpResponse response = Client.execute(request); contactsArray = null; resp = EntityUtils.toString(response.getEntity()); } catch (Exception e) { e.printStackTrace(); resp = "none is righteous"; } Log.e(TAG, "response is " + resp); return resp; }
void postData(JSONArray array, String teamname, String appurl) { // **** For Registering in Event ******/ String url = BackgroundFetch.BASE_URL + "/register/" + appurl; ArrayList param = new ArrayList<>(); HMac mac = new HMac(); param.add(new Pair<String, String>("hash", mac.getHash())); param.add(new Pair<String, String>("content", mac.getMessage())); param.add(new Pair<String, String>("userID", AllIDS.USER_anweshaID.substring(3))); if (teamname != null) param.add(new Pair<String, String>("name", teamname)); if (array != null) param.add(new Pair<String, String>("IDs", array.toString())); MyHttpClient client = new MyHttpClient( url, param, true, new MyHttpClientListener() { @Override public void onPreExecute() {} @Override public void onFailed(Exception e) { // pd.dismiss(); SplashMessage(name, "Registration Failed", android.R.drawable.ic_dialog_info); } @Override public void onSuccess(Object output) { String msg = "Not Registered"; String out = (String) output; try { JSONObject ob = new JSONObject(out); boolean status = ob.getBoolean("status"); msg = ob.getString("msg"); } catch (JSONException e) { e.printStackTrace(); } // pd.dismiss(); SplashMessage(name, msg, android.R.drawable.ic_dialog_info); } @Override public void onBackgroundSuccess(String result) {} }); client.context = this; // SplashMessage(name,"Registered",android.R.drawable.ic_dialog_info); }
public boolean uploadFile(File tosend, String name, String encoding) { MyHttpClient http = new MyHttpClient(context); // SSLSocketFactory ssl = // (SSLSocketFactory)http.getConnectionManager().getSchemeRegistry().getScheme( "https" // ).getSocketFactory(); // ssl.setHostnameVerifier( SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER ); // final String username = "******"; // final String password = "******"; // UsernamePasswordCredentials c = new UsernamePasswordCredentials(username,password); // BasicCredentialsProvider cP = new BasicCredentialsProvider(); // cP.setCredentials(AuthScope.ANY, c); // http.setCredentialsProvider(cP); HttpResponse res; try { HttpPost httpost = new HttpPost(host); MultipartEntity entity = new MultipartEntity(HttpMultipartMode.STRICT); FileBody isb = new FileBody(tosend, "application/*"); entity.addPart(name, isb); // for(int index=0; index < nameValuePairs.size(); index++) { // ContentBody cb; // if(nameValuePairs.get(index).getName().equalsIgnoreCase("File")) { // File file = new File(nameValuePairs.get(index).getValue()); // // // // /* // byte[] data = new byte[(int) file.length()]; // FileInputStream fis = new FileInputStream(file); // fis.read(data); // fis.close(); // // ByteArrayBody bab = new ByteArrayBody(data,"application/*","File"); // entity.addPart(nameValuePairs.get(index).getName(), bab); // */ // entity.addPart(nameValuePairs.get(index).getName(), isb); // } else { // // Normal string data // cb = new StringBody(nameValuePairs.get(index).getValue(),"", null); // entity.addPart(nameValuePairs.get(index).getName(),cb); // } // } httpost.setEntity(entity); res = http.execute(httpost); InputStream is = res.getEntity().getContent(); BufferedInputStream bis = new BufferedInputStream(is); if (bis.available() > 0) { byte[] buf = new byte[256]; bis.read(buf); Log.v("mark", "reading:" + new String(buf)); } else { Log.v("mark", "no response"); } return true; } catch (ClientProtocolException e) { Log.v("mark", "ClientProtocolException" + e.getMessage()); return true; } catch (IOException e) { Log.v("mark", "IOException" + e.getMessage()); return true; } }