Forum Xamarin.Forms

My request to datafeed returns null, when calling from my own android device

I have made an app which makes a request to a xmlfeed. When I try to send a request through the app from my own android device returns a blank result string. But when i try from the android emulator or UWP on my laptop, it returns the xmlstring. Im using Httpclient.

I have tried to call the request in the browser on the device, and it also returns the string with the correct values. When i debug it breaks at the deserializing, because the result string is "".

 public async Task<XmlData> GetAllDataForToday(DateTime dt)
 {
    HttpClient client = GetClient();
    string result = await client.GetStringAsync(Url + "getData.aspx? + "fromDate=" + dt + "&toDate=" + dt);
    XmlSerializer Deserializer = new XmlSerializer(typeof(XmlData), new XmlRootAttribute("XmlData"));
    var reader = new StringReader(result);
    XmlData DataCollection = (XmlData)Deserializer.Deserialize(reader);
    return DataCollection;
}

What could be the issue?

Answers

  • JarvanJarvan Member, Xamarin Team Xamurai

    What is result when debugging code? Check the return value of the request.

    HttpClient client = GetClient();
    string result = await client.GetStringAsync(Url + "getData.aspx? + "fromDate=" + dt + "&toDate=" + dt);
    
  • larzrazlarzraz Member ✭✭

    @jarvan
    The return value is: ""

  • larzrazlarzraz Member ✭✭

    I have send other requests to the same feed, which works on my device aswell. Only this one seems to be an issue.

  • JarvanJarvan Member, Xamarin Team Xamurai
    edited November 2019

    Is the url right? Check this part: "getData.aspx? + "fromDate=".

    It should be like:

    string Uri = "https://orgdev.azure-api.net/APIDev/Attendance?id=" + personID + "&timeofattendance=" + strAttn + "";
    
  • larzrazlarzraz Member ✭✭

    Thats correct. it works if i call it in the browser on my phone or postman. Then it returns the xml-string

  • JarvanJarvan Member, Xamarin Team Xamurai

    Have you tested on other phone devices? What's the result?

  • larzrazlarzraz Member ✭✭
    edited November 2019

    The same result. It returned "". But somehow it just started working, and i havent have the issue for days, without me changing anything

Sign In or Register to comment.