| 43 | | PostMethod post = new PostMethod(END_POINT); |
| 44 | | post.addParameter("key",key); |
| 45 | | post.addParameter("uri",uri); |
| 46 | | post.addParameter("size",size.toString()); |
| 47 | | post.setRequestHeader("User-agent", "Java Outputs Client"); |
| 48 | | new HttpClient().executeMethod(post); |
| 49 | | return post.getResponseBodyAsString(); |
| 50 | | } |
| | 46 | String response; |
| | 47 | StringBuilder sb = new StringBuilder(); |
| | 48 | |
| | 49 | URL urlObj = new URL(END_POINT); |
| | 50 | |
| | 51 | HttpURLConnection urlConnection = (HttpURLConnection)urlObj.openConnection(); |
| | 52 | urlConnection.setDoOutput(true); |
| | 53 | urlConnection.setRequestProperty("User-agent", "Java Outputz Client"); |
| | 54 | |
| | 55 | OutputStream os = urlConnection.getOutputStream(); |
| | 56 | |
| | 57 | StringBuilder postStr = new StringBuilder(); |
| | 58 | postStr.append("key=" + key); |
| | 59 | postStr.append("&size=" + size.toString()); |
| | 60 | postStr.append("&uri=" + uri); |
| | 61 | PrintStream ps = new PrintStream(os); |
| | 62 | ps.print(postStr); |
| | 63 | ps.close(); |
| | 64 | |
| | 65 | BufferedReader responsReader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); |
| | 66 | |
| | 67 | while ((response = responsReader.readLine()) != null) { |
| | 68 | sb.append(response); |
| | 69 | } |
| | 70 | |
| | 71 | responsReader.close(); |
| | 72 | urlConnection.disconnect(); |
| | 73 | return sb.toString(); |
| | 74 | |
| | 75 | } |
| | 76 | |