HttpMessageHandler Request Done and Error

Hi, im doing some http request that works perfect on Fuse preview and in Android devices, but in iOS, when i do the same request (and almost any request) the event Error is trigered along side with the Done request.

In IOS in the previous version of Fuse this work fine!

So, i trigger the request, it loads everything and then the function linked to Error is triggered.

im using Error as a “No Conection” error, i know that i should be using Timeout, but that doesnt work neither.

What can it be? How i can fix it?

void httpRequest(){

    string urlreqDetalle = "(URL DELETED)";
    urlreqDetalle = urlreqDetalle += apiKey;

    HttpMessageHandler msgdetalle = new HttpMessageHandler();

    var requestdet = msgdetalle.CreateRequest("GET", urlreqDetalle);

    requestdet.Done += DetallesPelicula;

    requestdet.Error += Error;

    requestdet.GetResponseContentString().ToString();

    requestdet.HttpResponseType = HttpResponseType.String;

    requestdet.SendAsync();

}

* Fuse version 0.1.2577

Hi, thanks for your bug report! The Http package saw a rewrite on both iOS and Android, so it’s likely that some new issues were introduced. If I understand correctly, you are seeing both Done and Error firing for the same request – Is this right?

I haven’t been able to reproduce that particular issue, but I posted a sample application I wrote at: https://gist.github.com/biochimia/fea40facb64b2f3efb20

Can you modify the example so it reproduces the issue you are seeing? I want to get a better understanding of the conditions under which the issue triggers.

Thanks Joao,

Yes, I am seeing both Done and Error firing for the same request. Or sometimes only error. The problem only happens on iPhone, and the requests involved in this problem are requests to parse.com. this problem only appeared on the newest version of Fuse, on the old one worked fine (using Experimental.Net).

My app does http request to 2 different servers using REST API, one is parse.com and the other is themoviedb.org, the problem is only when it make a request to parse.com.

I dug a little bit more and found a leak and a potential memory corruption bug, which I’ll fix, but I’m not sure this would consistently cause the issue you are seeing. I’ll leave you with a few questions for now.

  • Does the issue surface if you only make requests to parse.com?
  • How much data is being transferred or do you expect to be transferred per request?
  • Do you keep references to requests you send? And, if so, do you access the response’s content string outside the event handlers? (Doing this would currently make you vulnerable to the memory corruption issue I found on iOS)

Any other information you can share about the requests and feel is relevant in this case?

Q.-Does the issue surface if you only make requests to parse.com? A.-Only with parse.com and only on iOS.

Q.-How much data is being transferred or do you expect to be transferred per request? A.-Im only requesting some data from the database, the biggest request is like 16 vars and one of it is an array of strings that for now contain only 2 strings, that and i have a limit of 3.

Q.-Do you keep references to requests you send? And, if so, do you access the response’s content string outside the event handlers? (Doing this would currently make you vulnerable to the memory corruption issue I found on iOS) A.- i have all the vars on the void. this is the request:

Code not displaying correctly, ill repost it

what that does is get all the data from the database, add it to a new list and send the data to another class to append it to one stackpanel to dsplay the list. Everytime it is called, the stackpanel is cleared

void ReqMyMoviesAccount(string UserId){
    try{
    QueError = "ReqMyMoviesAccount";
    TriggerLoadingMyAccount.On = true;
    HttpMessageHandler MyMoviesList = new HttpMessageHandler();
    var createRequ = MyMoviesList.CreateRequest("GET","https://api.parse.com&order=-createdAt&count=1&limit=3&skip="+SkipValor);
createRequ.SetHeader("Content-type", "application/json"); createRequ.SetHeader("X-Parse-Application-Id",""); createRequ.SetHeader("X-Parse-REST-API-Key",""); createRequ.Done += ResMyMoviesAccount; createRequ.Error += Error; createRequ.GetResponseContentString(); createRequ.SetResponseType(HttpResponseType.String); createRequ.SendAsync(); }catch(Exception e){ debug_log e; } } void ResMyMoviesAccount(HttpMessageHandlerRequest request){
try{ SkipValor = SkipValor + 3; bool LikedByMe=false; var respJson = request.GetResponseContentString(); var jsonSerialized = JsonReader.Parse(respJson); var MyMovieList = new List<MyMovies>(); if(jsonSerialized["results"].Count != 0){ for(int i = 0; i < jsonSerialized["results"].Count;i++){ TotaldePeliculasP = jsonSerialized["count"].AsInteger(); var MyMoviesRes = jsonSerialized["results"][i]; var idPelicula = MyMoviesRes["IdPelicula"].AsString(); var Ano = MyMoviesRes["Ano"].AsString(); var Comentario = MyMoviesRes["Comentario"].AsString(); var Valor = MyMoviesRes["Valoracion"].AsFloat(); var date = MyMoviesRes["createdAt"].AsString(); var PosterPath = MyMoviesRes["PosterPath"].AsString(); var FramePath = MyMoviesRes["FramePath"].AsString(); var Likes = MyMoviesRes["Likes"].AsInteger(); var objectId = MyMoviesRes["objectId"].AsString(); var NombrePelicula = MyMoviesRes["NombrePelicula"].AsString(); var NombreUser = MyMoviesRes["FullName"].AsString(); var UserName = MyMoviesRes["UserName"].AsString(); var UserImg = MyMoviesRes["UserProfilePic"].AsString(); var UserId = MyMoviesRes["UserId"].AsString(); for(int a=0; a<MyMoviesRes["UsersLiked"].Count; a++){ if(UserIdLoggedInApp == MyMoviesRes["UsersLiked"][a].AsString()){ LikedByMe = true; } } MyMovieList.Add(new MyMovies(idPelicula, NombrePelicula, PosterPath, FramePath, objectId, Ano, Valor, Likes, date, Comentario, NombreUser, UserImg, LikedByMe, UserId, UserName)); LikedByMe = false; } foreach(var ml in MyMovieList){ var displaymovies = new Movie{ ml = this, MovieId = ml.MovieId, MovieNombre = ml.MovieNombre, MovieFrame = ml.MovieFrame, MovieObjectId = ml.MovieObjectId, MovieAno = ml.MovieAno, MovieValor = ml.MovieValor, MovieLikes = ml.MovieLikes, MovieDate = ml.MovieDate, MovieComent = ml.MovieComent, MoviePoster = ml.MoviePoster, NombreUser = ml.NombreUser, UserImg = ml.UserImg, Liked = ml.Liked, UserId=ml.UserId, UserName=ml.UserName, }; MyMoviesPosts.AddChild(displaymovies); } }else{ } }catch(Exception e){ debug_log e; } TriggerLoadingMyAccount.On = false; seguroRefreshScroll = false; }

Any news about this? My app in IOS dont work!

Thanks!

I have this GET method:

  void SendEmailData(string email,string password){
    try{
        HttpMessageHandler LogInReq = new HttpMessageHandler();
        var createRequ = LogInReq.CreateRequest("GET","https://api.parse.com/1/users?where={\"email\":\""+email.ToLower()+"\"}&count=1&quot;);        createRequ.SetHeader("Content-type", "application/json");
        createRequ.SetHeader("X-Parse-Application-Id","*APP ID");
        createRequ.SetHeader("X-Parse-REST-API-Key","REST API KEY*");
        createRequ.Done += GetEmailData;
        createRequ.Error += Error;
        createRequ.GetResponseContentString();
        createRequ.SetResponseType(HttpResponseType.String);
      createRequ.SendAsync();
    }catch(Exception e){
    }

}

This code in Fuse Preview works and in Android. But dont work in IOS…

In IOS if I remove from the url:

?where={\"email\":\""+email.ToLower()+"\"}&count=1");

Works, but with the complete url dont work!

We have some fixes in this area that are pending, but not released yet. Sorry for this taking some time.

In the new version (v0.5.3127) still have the same error! Any news in this? I cant test my app in IOS because my HTTP request have this structure:

http://url.com?where={\"email\":\""+email.ToLower()+"\"}&count=1");  

Also in android I have a problem when the URL contain characters like “$” and “^”.

Nothing about this topic?

Hey;

Do you get any errors when you use URL’s containing characters like $ and ^?

Yes, in Android. And in IOS when my URL contains variables likes this:

"http://myurl.com/where={\"VariableTitle\":\""+ MyVariable +"\"..."

Could you post the errors you get, so the issue can be investigated? An isolated testcase would also be awesome.

Also, remember to url encode the json you are trying to pass with where :slight_smile:

I dont get any error in the debug. In IOS the HTTP request that contains this structure always trigger the

Myrequest.Error += Error;

But in Android or in my Mac works perfect.

In Android when the url containing characters like $ and ^ I cant see the json results…

This is an example of the error in IOS:

  void SendEmailData(string email,string password){
  try{
    HttpMessageHandler LogInReq = new HttpMessageHandler();
    var createRequ = LogInReq.CreateRequest("GET","https://api.parse.com/1/users?where={\"email\":\""+email.ToLower()+"\"}&count=1");  
    createRequ.SetHeader("Content-type", "application/json");
    createRequ.SetHeader("X-Parse-Application-Id","*****APP ID****");
    createRequ.SetHeader("X-Parse-REST-API-Key","****REST API KEY*****");
    createRequ.Done += GetEmailData;
    createRequ.Error += Error;
    createRequ.GetResponseContentString();
    createRequ.SetResponseType(HttpResponseType.String);
    createRequ.SendAsync();
  }catch(Exception e){
  }
}

This code in Fuse Preview works and in Android. But dont work in IOS…

In IOS if I remove from the url:

?where={\"email\":\""+email.ToLower()+"\"}&count=1"); 

Works, but with the complete url dont work!

Ok, the search that didn’t work on android is fixed, the problem was that i was doing a request to a link with an space in a value, i changed the space with “%20” and now it works.

It was a search for users based on their full name, obviusly with a space between first and last name

The error in iOS is that the error function in “HttpMessageHandler.Error” is always triggered even when the http request it has succefully finished.

i think there is no url encode un Fuse or is not in the documentation, but i dont need it cos im encoding it manually, how is that? I’m adding all the parameters directly to the url of the request like this

https://api.parse.com/1/users?where={\"email\":\""+email.ToLower()+"\"}&count=1 

This error only happens with parse request with parameters, like the one i posted and only in iOS, this works on Android and CMake (and old preview)

Can anyone help us? I try replacing the ? to %3F and & to %26. But nothing! The request dont work…

How can I fix this in IOS?

Please!

Cristian : Thanks for reporting your issue. I’ve filed an internal ticket, and someone from the libs team will take a look at it Monday.

Thanks for your patience!

Thanks!