HttpClient not responding at first attempt

Hi everyone,
I am developing a cross platform mobile app, whenever I sent my app to release on Apple's App Store, my app is rejected because of connection problem. I detect the problem and it is caused by my rest api. To connect my server, there are fields that take server ip and port number, and I use these inputs to create query. After click login button, query is generated and system is tried to connect to the server, but main problem here is that, first connection attempt is not happened. When I run both server and client sides in debug mode, my request do not recieve to the server side. This happens only if app is installed to new device (if app is not installed before that device). If I relaunch app after closing it, connection is established and everything works as expected.

I use try catch block to get what is the error message but the problem never happen on my device and iphone/android emulators. Here is the codes both client and server side.

Client:

public async Task getData()
{
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Add("Accept", "application/json");

        DataModel model = new DataModel();

string addr = "http://" + txtServer.Text + ":" + txtPort.Text + "/Service/api/test/getData";

        var response = await client.PostAsync(addr,
            new StringContent(JsonConvert.SerializeObject(model),
            Encoding.UTF8, "application/json"));

        var result = await response.Content.ReadAsStringAsync();

        var res = JsonConvert.DeserializeObject<ResultStruct>(result);

        return JsonConvert.DeserializeObject<DataModel>
            (res.Data.ToString());
    }

Server:

[HttpPost]
[Route("getData")]
public ResultStruct getData()
{
ResultStruct result = new ResultStruct();
result.Result = true;
try
{
result.Data = getDataFromDB();
result.Message = "Success";
}
catch (Exception ex)
{
result.Result = false;
result.Message = ex.Message;
}
return result;
}

Posts

  • ChrisColeTechChrisColeTech USMember ✭✭✭

    I'm using the HttpClient in a similar way, and its working fine for me..

    You're definitely seeing a client side error, if the request never leaves the phone.

    what is the exact rejection message from Apple in your iTunes Connect?

  • TolgahanTuncTolgahanTunc USMember ✭✭

    They said:

    We discovered one or more bugs in your app when reviewed on iPad running iOS 11.3 on Wi-Fi connected to an IPv6 network.

    Specifically, your app displayed an error message after we entered the demo account credentials.

    Please see attached screenshots for details.

    The "displayed an error message" is showed by me when code is entered catch part, but I do not show the exception message directly on the message, I only display "Error occured, please try again." message. I uploaded a new version which shows exception message directly on the display error.

  • ChrisColeTechChrisColeTech USMember ✭✭✭
    edited April 2018

    Oh ok, that rejection message indicates something different. That's their IPv6 rejection letter.

    you need to make sure that your server is setup to support IPv6 (https://developer.apple.com/support/ipv6/)

    This jumped out at me from their docs:

    IMPORTANT: If you’re testing with a WWAN-capable device, make sure to turn off WWAN before running your test. This will ensure your device is using the IPv6-only Wi-Fi.

    Then they tell you how to turn off WWAN.

    So you'll need to turn off WWAN and test on your device/simulator to reproduce their test. Then, if you set a breakpoint in your try/catch, and drill down to the inner exception it may tell you a little more details.

    Test the app exactly the way they're testing and see what you come up with.

    More info on IPv6, and why Apple is now enforcing it:
    https://developer.apple.com/library/ios/documentation/NetworkingInternetWeb/Conceptual/NetworkingOverview/UnderstandingandPreparingfortheIPv6Transition/UnderstandingandPreparingfortheIPv6Transition.html#//apple_ref/doc/uid/TP40010220-CH213-SW1

  • TolgahanTuncTolgahanTunc USMember ✭✭

    Thank you so much, I will check my server's settings. By the way, they approved my app in the past and that is why I think my server (IIS 10) supports what they want.

  • TolgahanTuncTolgahanTunc USMember ✭✭

    Hi again,
    The error occurred on Apple side is "An error occurred while sending the request". This is the message of exception. Do you have any idea about this?

Sign In or Register to comment.