List of usage examples for org.apache.http.message BasicNameValuePair BasicNameValuePair
public BasicNameValuePair(String str, String str2)
From source file:postenergy.PostHttpClient.java
public static void main(String[] args) { HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost("http://iplant.dk/addData.php?n=mindass"); try {/* w ww.jav a2 s. c om*/ List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); nameValuePairs.add(new BasicNameValuePair("?n", "=mindass")); post.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = client.execute(post); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String line = ""; while ((line = rd.readLine()) != null) { System.out.println(line); if (line.startsWith("Input:")) { String key = line.substring(6); // do something with the key System.out.println("key:" + key); } } } catch (IOException e) { System.out.println("There was an error: " + e); } }
From source file:eu.seaclouds.platform.planner.core.PlannerClient.java
public static void main(String[] args) throws IOException { ArrayList<NameValuePair> params = new ArrayList<>(); params.add(new BasicNameValuePair("aam", "test http healper")); String content = new HttpHelper("http://localhost:8080").getRequest("/plan", params); System.out.println(content);/*w ww . java 2s . c om*/ content = new HttpHelper("http://localhost:8080").postRequest("/plan", params); System.out.println("POST!!!! " + content); // CloseableHttpClient httpclient = HttpClients.createDefault(); // // // HttpGet hhtpGet = new HttpGet("http://localhost:8080/plan?aam=qwerty"); // // // CloseableHttpResponse response2 = httpclient.execute(hhtpGet); // //// HttpPost httpPost = new HttpPost("http://targethost/login"); //// List <NameValuePair> nvps = new ArrayList <NameValuePair>(); //// nvps.add(new BasicNameValuePair("username", "vip")); //// nvps.add(new BasicNameValuePair("password", "secret")); //// httpPost.setEntity(new UrlEncodedFormEntity(nvps)); //// CloseableHttpResponse response2 = httpclient.execute(httpPost); // // try { // //System.out.println(response2.getStatusLine()); // HttpEntity entity2 = response2.getEntity(); // // do something useful with the response body // // and ensure it is fully consumed // // String content = new Scanner(entity2.getContent()).useDelimiter("\\Z").next(); // System.out.println(content); // // EntityUtils.consume(entity2); // } finally { // response2.close(); // } }
From source file:twiliotest.TwilioTest.java
public static void main(String[] args) throws TwilioRestException { TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN); // Build a filter for the MessageList List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("Body", "Testssss")); params.add(new BasicNameValuePair("To", "+639234026357")); params.add(new BasicNameValuePair("From", "+14803761083")); MessageFactory messageFactory = client.getAccount().getMessageFactory(); Message message = messageFactory.create(params); System.out.println(message.getSid()); }
From source file:twilio.SmsSender.java
public static void main(String[] args) throws TwilioRestException { TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN); Account account = client.getAccount(); MessageFactory messageFactory = account.getMessageFactory(); ArrayList params = new ArrayList(); params.add(new BasicNameValuePair("To", "+16464152856")); // Replace with a valid phone number for your account. params.add(new BasicNameValuePair("From", "+19899320208")); // Replace with a valid phone number for your account. params.add(new BasicNameValuePair("Body", "LOL!")); Message sms = messageFactory.create(params); }
From source file:com.ywh.train.Test.java
public static void main(String[] args) throws Exception { List<NameValuePair> parameters = new ArrayList<NameValuePair>(); parameters.add(new BasicNameValuePair("includeStudent", "00")); parameters.add(new BasicNameValuePair("orderRequest.from_station_telecode", "SHH")); parameters.add(new BasicNameValuePair("orderRequest.start_time_str", "00:00--24:00")); parameters.add(new BasicNameValuePair("orderRequest.to_station_telecode", "CSQ")); parameters.add(new BasicNameValuePair("orderRequest.train_date", "2011-11-24")); parameters.add(new BasicNameValuePair("orderRequest.train_no", "")); parameters.add(new BasicNameValuePair("seatTypeAndNum", "")); parameters.add(new BasicNameValuePair("trainClass", "QB#D#Z#T#K#QT#")); parameters.add(new BasicNameValuePair("trainPassType", "QB")); String responseBody = "0,<span id='id_5l0000D10502' class='base_txtdiv' onmouseover=javascript:onStopHover('5l0000D10502#AOH#CSQ') onmouseout='onStopOut()'>D105</span>,<img src='/otsweb/images/tips/first.gif'> <br> 09:08,<img src='/otsweb/images/tips/last.gif'> <br> 18:21,09:13,--,--,<font color='darkgray'></font>,<font color='#008800'></font>,--,--,--,--,--,--,--,<input type='button' class='yuding_u' onmousemove=this.className='yuding_u_over' onmousedown=this.className='yuding_u_down' onmouseout=this.className='yuding_u' onclick=javascript:getSelected('D105#553#09:08#5l0000D10502#AOH#CSQ') value=''></input>," + "<span id='id_5l0000D10502' class='base_txtdiv' onmouseover=javascript:onStopHover('5l0000D10502#EPH#PXG') onmouseout='onStopOut()'>D105</span>, ? <br> 09:38, ?? <br> 17:09,07:31,--,--,<font color='darkgray'></font>,<font color='darkgray'></font>,--,--,--,--,--,--,--,<input type='button' class='yuding_x' value=''></input>"; List<TrainQueryInfo> tqis = Util.parserQueryInfo(responseBody); for (TrainQueryInfo tqi : tqis) { System.out.println(tqi);//from ww w. ja v a 2 s . c o m } String citys = "@bji||BJP|0@bjn|?|VNP|1@bjx||BXP|2@cqb|?|CUW|3@sha||SHH|4@shn|?|SNH|5@shq||AOH|6@shx||SXH|7@tji||TJP|8@tjn|?|TIP|9@tjx||TXP|10@cch||CCT|11@cdd|?|ICW|12@cdu|?|CDW|13@csh||CSQ|14@csn|?|CWQ|15@fzh|?|FZS|16@fzn|??|FYS|17@gzb||GBQ|18@gzd||GGQ|19@gzh||GZQ|20@gzn|?|IZQ|21@heb||HBB|22@hfe|?|HFH|23@hkd|?|HMQ|24@hko|?|VUQ|25@hzh|?|HZH|26@hzn|??|XHH|27@jna|?|JNK|28@jnd|?|JAK|29@jnx|?|JGK|30@lzh||LZJ|31@nch|?|NCG|32@nji|?|NJH|33@njn|??|NKH|34@sjb||VVP|35@sjz||SJP|36@sya||SYT|37@syb||SBT|38@tyu||TYV|39@wha||WHN|40@xab||EAY|41@xan||XAY|42@zzh||ZZF|43@aya||AYF|44@bbu||BBH|45@bji|?|BJY|46@cna|??|CEH|47@czh||CZH|48@djy||DDW|49@dli||DLT|50@dsq||DQT|51@dzh||RXW|52@fdi|?|FES|53@han||AUH|54@hda||HDP|55@hko|?|HKN|56@hnx|?|EUH|57@hsh||HSP|58@hsh||HSN|59@jan|?|VAG|60@jgs||JGG|61@jhx|?|JBH|62@jji|?|JJG|63@jli|?|JLL|64@jsh||JUH|65@kfe|?|KFF|66@ksn|?|KNH|67@lan||UAH|68@lhe||LON|69@ljy|?|LKP|70@lym||LLF|71@lzh||LZD|72@nbd|?|NVH|73@nch|?|NCW|74@nto|?|NUH|75@pxi|??|PXG|76@pxx||PCW|77@qcs|?|QSW|78@qda|?|QDK|79@qzh||QEH|80@qzh||QYS|81@shg||SHD|82@sni|??|NIW|83@spi||SPT|84@sqi||SQF|85@sra||SRG|86@sya|??|SNN|87@sya||SEQ|88@szh|?|SZN|89@szh|?|SZH|90@szh||SZQ|91@tgu||TGP|92@tli|?|TLT|93@tsb|?|FUP|94@tsh|?|TSP|95@wch||WCN|96@wfd||WDT|97@wna|?|WNY|98@wxi||WXH|99@wys||WAS|100@wzn|?|VRH|101@xch||XCF|102@xhu||EFQ|103@xmb||XKS|104@xme||XMS|105@xxi||XXF|106@xya||XUN|107@xya||XFN|108@xyu||XUG|109@xzh|?|XCH|110@yan||YWY|111@ych|?|AFH|112@ych||YCG|113@yta||YTG|114@ywu||YWH|115@yxi||YON|116@yzh||YLH|117@zbo|?|ZBK|118@zhb|?|ZIQ|119@zji||ZJH|120@zmd||ZDN|121@zzh||ZZQ|122@zzh||ZEK|123@zzx||ZFK|124@aji||ARH|125@atb||ASH|126@bao|?|BWQ|127@bbn|?|BMH|128@bdh||BEP|129@bdi|?|BDP|130@bhs|??|BWH|131@bji||IBQ|132@bji||BLQ|133@cbb|?|CIN|134@cle|?|CLK|135@czb||ESH|136@czh|?|CXH|137@czx||ICQ|138@czx||CBP|139@dan||DAG|140@dgu||DAQ|141@dsh|?|DRQ|142@dtu||RUH|143@dya||DYH|144@dyb||EXH|145@dyd||IAW|146@dyu||EWH|147@dzd||DIP|148@dzh||DXP|149@ezh||ECN|150@fan|?|FAS|151@fdo||FIH|152@fhu||FHH|153@fqi|?|FQS|154@gmi||GMK|155@gqc|?|GAG|156@gyn|?|GYF|157@gzh|?|GNQ|158@hax||HIH|159@hax||VXN|160@hch|??|WKW|161@hgz||IGW|162@hji||HJS|163@hlb||HPD|164@hni|?|HNH|165@hqi||VQH|166@hsb|?|HDY|167@hsh||VCH|168@hsx||HEQ|169@hyd||HVQ|170@hzh||VON|171@jji||JJS|172@jme||JWQ|173@jsb||EGH|174@jsn|?|EAH|175@jxi||JXH|176@jxn|?|EPH|177@jzb||JZK|178@jzh||JZH|179@jzn|?|JOD|180@lbx|??|LPF|181@lch|?|UCK|182@lfa|?|LJP|183@lha||UFH|184@lji||LKS|185@lsh|?|LSG|186@lsh||LIQ|187@lxi||UXP|188@lyo||LMH|189@lyu|?|LVS|190@lyx||LPQ|191@mcb||MBN|192@mcn|?|MNF|193@mla||MHQ|194@mld||MQQ|195@nde|?|NES|196@nha|?|NHH|197@nla|?|NNQ|198@nxb|?|NEH|199@pjb||PBD|200@pti||PTS|201@qfd||QAK|202@qha|?|QYQ|203@qji||INH|204@qsy||QYH|205@qyu||QBQ|206@qzs|?|QZK|207@ran||RAH|208@rch||RCG|209@rgu||RUQ|210@sde||ORQ|211@sfa|?|OLH|212@sgu||SNQ|213@sjn|??|IMH|214@slo||SLQ|215@smn|?|SCF|216@smx||OQH|217@sxi|?|SOH|218@syu||BDH|219@szb||SND|220@szb|?|OHH|221@szd||SRH|222@szq|?|ITH|223@szq|?|KAH|224@tan|?|TID|225@tan||TMK|226@tms||TLS|227@tna|?|TVW|228@txi|?|TCH|229@tzd||TEK|230@tzh|?|TZH|231@wch||WEQ|232@wfa|??|WFK|233@wli||VHH|234@wnb|?|WBY|235@wni|?|WNQ|236@wqi||WWP|237@wxd||WGH|238@wxq||IFH|239@xga|?|XGN|240@xla|?|EAQ|241@xli||XPH|242@xnb|?|XRN|243@xpu||XOS|244@xpu||XIW|245@xta|?|XTP|246@xzd|?|UUH|247@ych||AIH|248@yds|??|YGH|249@yha|?|EVH|250@yji||URH|251@ylw||TWQ|252@ylz|?|YSY|253@yqb||YPP|254@yqi|?|UPH|255@yxi||ACG|256@yya||YYH|257@yyd||YIQ|258@zji||ZDH|259@zjn|?|ZEH|260@zmt||ZOQ|261@zqi||ZTK|262@zsb||ZGQ|263@zsh||ZSQ|264@zzx||ZAQ|265"; String city[] = citys.split("@"); System.out.println("---------start--------"); for (String tmp : city) { System.out.println(tmp); } System.out.println("---------end--------"); //String test = "? ? ?? ? ? ? ? --> ?? ??? : 260.0()--> ? Sat Nov 26 14:04:16 CST 2011 1 ? ?? ? ? Mon Nov 28 00:00:00 CST 2011 D105 Thu Jan 01 09:08:00 CST 1970 02 052 ?, 260.0 ? --> --> ??"; String test = "1 vxv"; System.out.println(test.replaceAll("\\s", "")); }
From source file:com.programming4food.smssender.Main.java
public static void main(String[] args) throws TwilioRestException { int maxThreads = 8; int minThreads = 2; int timeOutMillis = 30000; threadPool(maxThreads, minThreads, timeOutMillis); port(1234);/* w w w .ja va2s.c o m*/ get("/hello", (req, res) -> "Api Iniciada"); post("/sendMSG", (req, res) -> { try { String numero = req.queryParams("numero"); String oficio = req.queryParams("oficio"); String cliente = req.queryParams("cliente"); TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN); List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("Body", "El numero +" + cliente + " requiere tus servicios como " + oficio)); params.add(new BasicNameValuePair("To", "+" + numero)); params.add(new BasicNameValuePair("From", "+12563440285")); MessageFactory messageFactory = client.getAccount().getMessageFactory(); Message message = messageFactory.create(params); System.out.println(message.getStatus()); return "Exito"; } catch (Exception ex) { ex.printStackTrace(); return "Error"; } }, new JsonTransformer()); System.out.println("Iniciada"); }
From source file:postenergy.TestHttpClient.java
public static void main(String[] args) { HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost("https://www.google.com/accounts/ClientLogin"); try {/* w w w. jav a 2s . co m*/ List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); nameValuePairs.add(new BasicNameValuePair("Email", "youremail")); nameValuePairs.add(new BasicNameValuePair("Passwd", "yourpassword")); nameValuePairs.add(new BasicNameValuePair("accountType", "GOOGLE")); nameValuePairs.add(new BasicNameValuePair("source", "Google-cURL-Example")); nameValuePairs.add(new BasicNameValuePair("service", "ac2dm")); post.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = client.execute(post); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String line = ""; while ((line = rd.readLine()) != null) { System.out.println(line); if (line.startsWith("Auth=")) { String key = line.substring(5); // do something with the key } } } catch (IOException e) { e.printStackTrace(); } }
From source file:org.hcmut.emr.SessionBuilder.java
public static void main(String[] args) throws FileNotFoundException, IOException { try (BufferedReader br = new BufferedReader( new FileReader("/home/sinhlk/myspace/emr/src/main/resources/patern"))) { ObjectMapper jsonMapper = new ObjectMapper(); String line = br.readLine(); Map<String, String> result = new HashMap<String, String>(); List<NameValuePair> list = new ArrayList<>(); while (line != null) { if (line != null && line != "") { list.add(new BasicNameValuePair(line.trim().toLowerCase(), SessionBuilder.buildValue(line))); result.put(line.trim().toLowerCase(), SessionBuilder.buildValue(line)); line = br.readLine();/*w w w.j av a 2s . c om*/ } } System.out.println(jsonMapper.writeValueAsString(list)); File file = new File("/home/sinhlk/myspace/emr/src/main/resources/session.js"); jsonMapper.writeValue(file, list); } }
From source file:org.openeclass.EclassMobile.java
public static void main(String[] args) { try {// w ww. j a va2s .c o m HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("https://myeclass/modules/mobile/mlogin.php"); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("uname", mUsername)); nvps.add(new BasicNameValuePair("pass", mPassword)); httppost.setEntity(new UrlEncodedFormEntity(nvps)); System.out.println("twra tha kanei add"); System.out.println("prin to response"); HttpResponse response = httpclient.execute(httppost); StatusLine status = response.getStatusLine(); if (status.getStatusCode() != 200) System.out.println("Invalid response from server: " + status.toString()); System.out.println("meta to response"); Header[] head = response.getAllHeaders(); for (int i = 0; i < head.length; i++) System.out.println("to head exei " + head[i]); System.out.println("Login form get: " + response.getStatusLine()); HttpEntity entity = response.getEntity(); InputStream ips = entity.getContent(); BufferedReader buf = new BufferedReader(new InputStreamReader(ips, "UTF-8"), 1024); StringBuilder sb = new StringBuilder(); String s = ""; while ((s = buf.readLine()) != null) { sb.append(s); } System.out.println("to sb einai " + sb.toString()); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:ClientWithResponseHandlerPost.java
public final static void main(String[] args) throws Exception { CloseableHttpClient httpclient = HttpClients.createDefault(); try {/*w ww.j a v a2 s. com*/ List<NameValuePair> formparams = new ArrayList<NameValuePair>(); formparams.add(new BasicNameValuePair("id", "KYacxNZ6QQc")); formparams.add(new BasicNameValuePair("calid", "adamm")); formparams.add(new BasicNameValuePair("content-out", "text/xml")); UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, Consts.UTF_8); //entity.setChunked(true); HttpPost httppost = new HttpPost("http://localhost:8080/export.wcap"); httppost.setEntity(entity); System.out.println("executing request " + httppost.getURI()); System.out.println("executing request " + httppost.getConfig()); // Create a custom response handler ResponseHandler<String> responseHandler = new ResponseHandler<String>() { public String handleResponse(final HttpResponse response) throws ClientProtocolException, IOException { int status = response.getStatusLine().getStatusCode(); if (status >= 200 && status < 600) { HttpEntity entity = response.getEntity(); return entity != null ? EntityUtils.toString(entity) : null; } else { throw new ClientProtocolException("Unexpected response status: " + status); } } }; String responseBody = httpclient.execute(httppost, responseHandler); System.out.println("----------------------------------------"); System.out.println(responseBody); System.out.println("----------------------------------------"); } finally { httpclient.close(); } }