java - I want to get a String return type for a http response i get for http post request i trigger -


i want string return type http response http post request trigger, return variable giving error

"message cannot resolved variable"

subsequently have convert return string value json string data.

here code....

public string sendpost(string _postdata) {      closeablehttpclient httpclient = httpclients.createdefault();     httppost httppost = new httppost(post_url);     httppost.addheader("user-agent", user_agent);      stringentity entity = new stringentity(_postdata, http.utf_8);     entity.setcontenttype("application/json");     httppost.setentity(entity);      closeablehttpresponse httpresponse;     try {         httpresponse = httpclient.execute(httppost);          system.out.println("post response status:: " + httpresponse.getstatusline().getstatuscode());          bufferedreader reader = new bufferedreader(new inputstreamreader(httpresponse.getentity().getcontent()));          string inputline;         stringbuffer response = new stringbuffer();          while ((inputline = reader.readline()) != null) {             response.append(inputline);              string message = org.apache.commons.io.ioutils.tostring(reader);             string type = message.getclass().getname();              system.out.println(type);             system.out.println("final : " + message);         }         reader.close();          // print result         system.out.println(response.tostring());         httpclient.close();     } catch (clientprotocolexception e) {         e.printstacktrace();     } catch (ioexception e) {         e.printstacktrace();     }     return message;   } 

because local "message" variable using outside of loop. add global "message" variable, should solve problem.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -