简体   繁体   中英

How to get value of HttpResponseMessage like HttpStatusCode Using Koush ION

Here is How I returned HttpResponseMessage from my ASP.net server like

return Request.CreateResponse(HttpStatusCode.OK,"some string");

And I have accessed the returned response in android with Kaush ION like this

Ion.with(LoginActivity.this)
                    .load("--URL TO POST--")
                    .setJsonObjectBody(jsonToSubmit)
                    .asJsonObject()
                    .withResponse()
                    .setCallback(new FutureCallback<Response<JsonObject>>() {
                        @Override
                        public void onCompleted(Exception e, Response<JsonObject> result) {
                            //I want to access header information here
                         }

Inside onCompleted Method I can easily access HttpStatusCode like

int code = result.getHeaders().code();

OR

String statusCode = result.getHeaders().message();

Now My Question is :

How can I get that "some string" which was sent in HttpResponseMessage with HttpStatusCode ?

----Here is the solution-----

Create a model class StringMsg.cs

public class StringMsg
{
    public string Message { get; set; }
}

If you want to send string message and want to retrieve that send it like

StringMsg str = new StringMsg();
str.Message = "some string";
return Request.CreateResponse(HttpStatusCode.OK, str);

Finally, Retrieve The String in onCompleted Method like this

 @Override
  public void onCompleted(Exception e, Response<JsonObject> result) {

      JsonObject result1 = result.getResult();
      String myResult = result1.get("Message"); // Result

   }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM