java - Retrieve get response with Android -


I have app android that receives requests for a servlet in an asynchronous 2. I want to retrieve a string in which there is a simple response. This is my AsyncTask:

  protected string doInBackground (zero ... parameter) {upload upload file (); } @SuppressWarnings ("deprecation") Private string upload file () {string response string = null; String reaction: = zero; HTTP Client HTTP Client = New DefaultHttpClient (); Http post httppost = new HTTP post (Config.FILE_UPLOAD_URL); {AndroidMultiPartEntity Entity = New AndroidMultiPartEntity (New ProgressListener) {@Override Public Nil Transfer (long number) {publishProgress ((int) ((num / (float) totalSize) * 100));}}); File source file = new file (file path); // file file to extract the HTIT unit.edit ("image", new file body (source file)); TotalSize = entity.getContentLength (); Httppost.setEntity (unit); // Create server call HttpResponse response = httpclient.execute (httppost); HttpEntity r_entity = response.getEntity (); Int statusCode = response.getStatusLine (). GetStatusCode (); If (statusCode == 200) {// server response response string = EntityUtils.toString (r_entity); Try {HTTP Client Client = New DefaultHttpClient (); URI getURL = new URI ("http://192.168.1.101:8080/MusaServlet?collection=" + collection + "& amp; name =" + filename); Log.i ("QUERY", getURL.getQuery ()); Get HTTP Gate = New HTTP Gate (Homescreen); HTTP response response = gateway Exempt (Receive); HttpEntity resEntityGet = responseGet.getEntity (); If (resEntityGet! = Null) {Log.i ("get feedback", EntityUtils.toString (resEntityGet)); } ResponseStr = EntityUtils.toString (responseGet.getEntity ()); } Hold (exception e) {e.printStackTrace (); }} And {responseString = "Error occurred! HTTPPosition code:" + statusCode; }} Hold (Client Protocol Execution E) {responseString = e.toString (); } Hold (IOException e) {responseString = e.toString (); } Return response; }  

The servlet code is instead:

  PrintWriter = out response.getWriter (); Out.println ("Hello STUPID APP!");  

However the dialog shown by the app is empty! No words! What is the problem?

Thank you

First check your GET request status code as < P>

  responseGet.getStatusLine (). GetStatusCode (); If the number is giving 200 then  GET  is successful. 
Now if you have 200, you will receive the response sent by the following code
P>
  HTTT resentgate = responsegate.gatientity ();  

and then

  string results; If (resEntityGet! = Null) {Results = EntityUtils.toString (resEntityGet); }  

Now the most important thing is that once you enter the responseGet.getEntity () GAT response will be passed to the data variable .. you assign ..

>

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -