Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [HttpPost]
- public HttpResponseMessage RetrieveString(String longString)
- {
- var resp = new HttpResponseMessage()
- {
- Content = new StringContent("{"ResultString":"" + longString + ""}")
- };
- resp.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
- return resp;
- }
- protected String doInBackground(String... params) {
- HttpURLConnection urlConnection = null;
- BufferedReader reader = null;
- String JSONStr = null;
- try {
- final String URL = "http://172.27.179.197:7837/api/TestCon/RetrieveString?";
- Uri builtUri = Uri.parse(URL).buildUpon()
- .appendQueryParameter("longString", params[0]).build();
- URL url = new URL(builtUri.toString());
- urlConnection = (HttpURLConnection) url.openConnection();
- urlConnection.setRequestMethod("POST");
- urlConnection.setRequestProperty("connection", "keep-alive");
- urlConnection.setRequestProperty("Content-Type", "multipart/form-data");
- urlConnection.connect();
- InputStream inputStream = urlConnection.getInputStream();
- StringBuffer buffer = new StringBuffer();
- if (inputStream == null) {
- return null;
- }
- reader = new BufferedReader(new InputStreamReader(inputStream));
- String line;
- while ((line = reader.readLine()) != null) {
- buffer.append(line + "n");
- }
- if (buffer.length() == 0) {
- return null;
- }
- JSONStr = buffer.toString();
- } catch (IOException e) {
- Log.e(LOG_TAG, "Error ", e);
- return null;
- } finally {
- if (urlConnection != null) {
- urlConnection.disconnect();
- }
- if (reader != null) {
- try {
- reader.close();
- } catch (final IOException e) {
- Log.e(LOG_TAG, "Error closing stream", e);
- }
- }
- }
- return JSONStr;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement