NSHttpURLResponse contains different values on device than on simulator from xamarin iOS app

796 views Asked by At

I am making an iPhone app on xamarin. I am encountering a very baffling issue. I am making an NSURLConnection to a link to get the cookie information from header and use that cookie to open other protected links. In connection:didReceiveResponse: method, the NSHttpURLResponse contains the "Set-Cookie" field to retrieve. I am getting the correct header information when running the application on simulator. But on device, the same code does not return the complete header with cookie. This prevents me from calling other links as well. If I run contact the same url from a native sample app in objective-c, I get the correct header information. It is only not working on device from xamarin app.

The code for creating a connection is

NSMutableUrlRequest request = new NSMutableUrlRequest(url);
request.HttpMethod = "GET";
request.ShouldHandleCookies = true;
request.Headers = header;
URLConnDelegate connectionDelegate = new URLConnDelegate (this);
NSUrlConnection connection = new NSUrlConnection (request, connectionDelegate, true);

And the code for receiving response is

public override void ReceivedResponse (NSUrlConnection connection, NSUrlResponse response)
    {
        NSHttpUrlResponse httpResponse = response as NSHttpUrlResponse;
        Console.WriteLine (httpResponse.AllHeaderFields);
        NSString cookieStr = httpResponse.AllHeaderFields.ValueForKey (new NSString ("Set-Cookie")) as NSString;
        caller.setCookie (cookieStr);
        NSMutableUrlRequest request = new NSMutableUrlRequest (new NSUrl(caller.urlString));
        caller.loadRequest (request);
    }

The set-cookie field is not coming when I run it from device.

Any help would be much appreciated.

Thanks

0

There are 0 answers