How to fix "Exception occured: [Sitecore Mobile SDK] Public key not received properly"?

532 views Asked by At

I'm working on Sitecore Mobile SDK with Sitecore 8. I'm facing the exception as below :

Exception occured: [Sitecore Mobile SDK] Public key not received properly

The similar this post https://forums.xamarin.com/discussion/44352/sitecore-mobile-sdk-for-xamarin

How I can fix this bug ?

Update

My code (Ref: https://components.xamarin.com/view/Sitecore.Mobile.SDK):

private async Task<string> GetContent()
    {
        var instanceUrl = "http://sitecore.local";
        using (var credentials = new SecureStringPasswordProvider("admin", "b"))
        using
        (
            var session = SitecoreWebApiSessionBuilder.AuthenticatedSessionWithHost(instanceUrl)
                            .Credentials(credentials)
                            .WebApiVersion("v1")
                            .DefaultDatabase("web")
                            .DefaultLanguage("en")
                            .MediaLibraryRoot("/sitecore/media library")
                            .MediaPrefix("~/media/")
                            .DefaultMediaResourceExtension("ashx")
                            .BuildSession()
        )
        {
            var request = ItemWebApiRequestBuilder.ReadItemsRequestWithPath("/sitecore/content/home")
                            .Database("web")
                            .Language("en")
                            .Build();
            try
            {
                var respond = await session.ReadItemAsync(request);

                ISitecoreItem item = respond[0];
                var strContent = item["Title"].RawValue;

                return strContent;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception occured: " + ex.Message);
            }
            return "";
        }
    }

Update 1 :

@Trayek, I updated my question: From "sdn.sitecore.net/upload/sdn5/modules/sitecore%20item%20web%20api/sitecore_item_web_api_developer_guide_sc66-71-usletter.pdf". I have been changed the security on Sitecore.ItemWebApi.config and Sitecore.Speak.ItemWebApi.config. Simulator: I tested on Genymotion and Xamarin_Android_API_15.

1

There are 1 answers

3
Trayek On BEST ANSWER

First of all, I'm assuming you've enabled the Sitecore Item Web API. If not that will also give this issue.

When I've had this bug, I followed the steps in this blog post which fixed it for me.

The short of it is: An emulator won't be using your hosts file, but instead it's own. So the emulator won't know what http://sitecore.local is, which means Sitecore can't validate it can talk to it.

The blog post shows you how to update the host file of the emulator so you can still use http://sitecore.local.