• About Us
  • Blog
  • Basket
  • Account
  • Sign In
  •  

Forums

PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 22 Jan 2016 02:55 PM by  VR
Call returns xml instead of json
 5 Replies
Sort:
You are not authorized to post a reply.
Author Messages

VR



New Member


Posts:5
New Member


--
14 Jan 2016 12:00 PM
    I get xml in the response occasionally, which causes the serializer to error out trying to deserialize the response. It happened once in the test environment over the weekend and now once in production. I just started testing this last week and moved it into production this morning at around 5:00 AM CST.

    Am I passing through some header that is affecting the response type?

    Is there a query string parameter I should pass to ensure the response type is json?

    Here is a sample response from 5:40 AM CST this morning:
    Basic00Exact1172622172963503474180922016-01-06T00:00:00Z0Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us; Silk/1.0.146.3-Gen4_12000410) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16 Silk-Accelerated=trueMozilla/5.0 (Macintosh; Intel Mac OS X 10_6 ; Silk/1.0 Safari/533 Silk-Accelerated=trueIsMobileTrueIsTabletTrue
    0

    VR



    New Member


    Posts:5
    New Member


    --
    14 Jan 2016 05:48 PM
     <Match xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/DetectorRole.Models"><DataSetName>Basic</DataSetName><DetectionTime>0</DetectionTime><Difference>0</Difference><Method>Exact</Method><ProfileIds xmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays"><d2p1:KeyValueOfintint><d2p1:Key>1</d2p1:Key><d2p1:Value>19891</d2p1:Value></d2p1:KeyValueOfintint><d2p1:KeyValueOfintint><d2p1:Key>2</d2p1:Key><d2p1:Value>46229</d2p1:Value></d2p1:KeyValueOfintint><d2p1:KeyValueOfintint><d2p1:Key>3</d2p1:Key><d2p1:Value>47185</d2p1:Value></d2p1:KeyValueOfintint><d2p1:KeyValueOfintint><d2p1:Key>4</d2p1:Key><d2p1:Value>18092</d2p1:Value></d2p1:KeyValueOfintint></ProfileIds><Published>2016-01-06T00:00:00Z</Published><SignaturesCompared>0</SignaturesCompared><TargetUseragent>Mozilla/5.0 (Linux; U; Android 2.3.6; en-us; SAMSUNG-SGH-I717 Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1</TargetUseragent><UserAgent>Mozilla/5.0 (Linux; U; Android 2.3.6;        SAMSUNG-SGH-I717 Build/GINGERBREAD  AppleWebKit/533.                      Version/4.0 Mobile Safari/533</UserAgent><Values xmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays"><d2p1:KeyValueOfstringArrayOfstringty7Ep6D1><d2p1:Key>IsMobile</d2p1:Key><d2p1:Value><d2p1:string>True</d2p1:string></d2p1:Value></d2p1:KeyValueOfstringArrayOfstringty7Ep6D1><d2p1:KeyValueOfstringArrayOfstringty7Ep6D1><d2p1:Key>IsTablet</d2p1:Key><d2p1:Value><d2p1:string>False</d2p1:string></d2p1:Value></d2p1:KeyValueOfstringArrayOfstringty7Ep6D1></Values></Match>
    0

    Ben Shillito



    New Member


    Posts:9
    New Member


    --
    18 Jan 2016 12:10 PM
    Hi,

    So far I have failed to recreate this problem with any of our cloud instances, I am currently looking through the logs to see if there is more information about what you were returned.
    I assume as most of your responses come back fine you're using the proper format of cloud.51degrees.com/api/v1/LICENCE KEY/match?user-agent=... So is the text you pasted above the raw response from this, or has it been parsed in some way?
    It would also help me to know what environment you are using this in.

    Ben
    0

    VR



    New Member


    Posts:5
    New Member


    --
    18 Jan 2016 03:25 PM
    What I posted is the raw response. I am requesting it with only the properties "IsMobile+IsTablet"

    It happened 89 times in one day in our production environment. I did write a workaround to deserialize the xml if that is what is returned. I moved that in on Friday morning. By the way it would be nice if you would provide a wsdl file, since this seems to be written in WCF based on the xml responses.

    string response_string = null;
    
                try
                {
                    //get the string in case we need to log the response
                    response_string = GetApiResponse(EndpointAddress, headers, TimeoutInMilliseconds);
                }
                catch (System.Net.WebException ex)
                {
                    if (ex.Response != null)
                    {
                        System.IO.Stream dataStream = ex.Response.GetResponseStream();
                        //// Open the stream using a StreamReader for easy access.
                        System.IO.StreamReader reader = new System.IO.StreamReader(dataStream);
                        //// Read the content.
                        string responseFromServer = reader.ReadToEnd();
                        responseFromServer = responseFromServer.Replace("\r\n", "");
    
                        throw new Exception("Api Error", new Exception("Error accessing url: " + EndpointAddress, new Exception("Response from server: " + responseFromServer, ex)));
                    }
                    else
                    {
                        throw new Exception("Api Error", new Exception("Error accessing url: " + EndpointAddress, ex));
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("Api Error", new Exception("Error accessing url: " + EndpointAddress, ex));
                }
    
                Stream response_stream = GenerateStreamFromString(response_string);
    
                XmlMatch resp;
    
                try
                {                
                    DataContractJsonSerializerSettings serset = new DataContractJsonSerializerSettings();
                    serset.UseSimpleDictionaryFormat = true; //required to set dictionary format of the serializer options to pull the data type correctly
    
                    DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(XmlMatch), serset);
                    
                    resp = (XmlMatch)ser.ReadObject(response_stream);                
                }
                catch (Exception ex)
                {
                    //some kind of error condition causes the response to be xml sometimes
                    if (ex.Message.Contains("Encountered unexpected character &#39;<&#39;."))
                    {
                        try
                        {
                            //reset the stream position for reading
                            response_stream.Position = 0;
    
                            DataContractSerializer ser = new DataContractSerializer(typeof(XmlMatch));
                            resp = (XmlMatch)ser.ReadObject(response_stream);
                        }
                        catch (Exception ex2)
                        {
                            throw new Exception("Error deserializing response stream xml: \r\n" + response_string, ex2);
                        }
                    }
                    else
                    {
                        throw new Exception("Error deserializing response stream: \r\n" + response_string, ex);
                    }
                }
    
    //the XmlMatch class is in another library but I use just one and deserialize from either json or xml as illustrated above
    //at first I had two classes based on the response type of json or xml but I cleaned it up to use just the one class
    namespace FiftyOneDegreesCloud
    {
        [DataContract(Namespace = "http://schemas.datacontract.org/2004/07/DetectorRole.Models", Name = "Match")]
        internal class XmlMatch
        {
            [DataMember]
            public string DataSetName { get; set; }
    
            [DataMember]
            public int DetectionTime { get; set; }
    
            //[DataMember]
            //public int[] ProfileIds { get; set; }
    
            [DataMember]
            public Dictionary<string, string[]> Values { get; set; }
        }
    }
     


    More samples of errors

     
    System.Exception: Error deserializing response stream:   <Match xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/DetectorRole.Models"><DataSetName>Basic</DataSetName><DetectionTime>0</DetectionTime><Difference>0</Difference><Method>Exact</Method><ProfileIds xmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays"><d2p1:KeyValueOfintint><d2p1:Key>1</d2p1:Key><d2p1:Value>15767</d2p1:Value></d2p1:KeyValueOfintint><d2p1:KeyValueOfintint><d2p1:Key>2</d2p1:Key><d2p1:Value>48843</d2p1:Value></d2p1:KeyValueOfintint><d2p1:KeyValueOfintint><d2p1:Key>3</d2p1:Key><d2p1:Value>17138</d2p1:Value></d2p1:KeyValueOfintint><d2p1:KeyValueOfintint><d2p1:Key>4</d2p1:Key><d2p1:Value>18092</d2p1:Value></d2p1:KeyValueOfintint></ProfileIds><Published>2016-01-06T00:00:00Z</Published><SignaturesCompared>0</SignaturesCompared><TargetUseragent>Mozilla/5.0 (iPad; U; CPU OS 4_3_5 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8L1 Safari/6533.18.5</TargetUseragent><UserAgent>Mozilla/5.0 (iPad;    CPU OS 4_3_5      Mac OS X;        AppleWebKit/533.                         Version/5.0   Mobile     Safari/653</UserAgent><Values xmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays"><d2p1:KeyValueOfstringArrayOfstringty7Ep6D1><d2p1:Key>IsMobile</d2p1:Key><d2p1:Value><d2p1:string>True</d2p1:string></d2p1:Value></d2p1:KeyValueOfstringArrayOfstringty7Ep6D1><d2p1:KeyValueOfstringArrayOfstringty7Ep6D1><d2p1:Key>IsTablet</d2p1:Key><d2p1:Value><d2p1:string>True</d2p1:string></d2p1:Value></d2p1:KeyValueOfstringArrayOfstringty7Ep6D1></Values></Match> ---> System.Runtime.Serialization.SerializationException: There was an error deserializing the object of type FiftyOneDegreesCloud.Match. Encountered unexpected character &#39;<&#39;. ---> System.Xml.XmlException: Encountered unexpected character &#39;<&#39;.     at System.Xml.XmlExceptionHelper.ThrowXmlException(XmlDictionaryReader reader, XmlException exception)     at System.Runtime.Serialization.Json.XmlJsonReader.ReadAttributes()     at System.Runtime.Serialization.Json.XmlJsonReader.Read()     at System.Xml.XmlBaseReader.IsStartElement()     at System.Xml.XmlBaseReader.IsStartElement(XmlDictionaryString localName, XmlDictionaryString namespaceUri)     at System.Runtime.Serialization.Json.DataContractJsonSerializer.InternalIsStartObject(XmlReaderDelegator reader)     at System.Runtime.Serialization.Json.DataContractJsonSerializer.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName)     at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)     --- End of inner exception stack trace ---     at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)     at System.Runtime.Serialization.Json.DataContractJsonSerializer.ReadObject(XmlDictionaryReader reader)     at FiftyOneDegreesCloud.FiftyOneDegreesCloudClient.GetMatch(String HtmlEncodedUserAgent, NameValueCollection headers)     --- End of inner exception stack trace ---     at FiftyOneDegreesCloud.FiftyOneDegreesCloudClient.GetMatch(String HtmlEncodedUserAgent, NameValueCollection headers)     at meyerreweb.SiteVersionSelector.SetNewSiteVersionCookie()
    
    System.Exception: Error deserializing response stream:   <Match xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/DetectorRole.Models"><DataSetName>Basic</DataSetName><DetectionTime>0</DetectionTime><Difference>0</Difference><Method>Exact</Method><ProfileIds xmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays"><d2p1:KeyValueOfintint><d2p1:Key>1</d2p1:Key><d2p1:Value>15364</d2p1:Value></d2p1:KeyValueOfintint><d2p1:KeyValueOfintint><d2p1:Key>2</d2p1:Key><d2p1:Value>7133</d2p1:Value></d2p1:KeyValueOfintint><d2p1:KeyValueOfintint><d2p1:Key>3</d2p1:Key><d2p1:Value>17250</d2p1:Value></d2p1:KeyValueOfintint><d2p1:KeyValueOfintint><d2p1:Key>4</d2p1:Key><d2p1:Value>18092</d2p1:Value></d2p1:KeyValueOfintint></ProfileIds><Published>2016-01-06T00:00:00Z</Published><SignaturesCompared>0</SignaturesCompared><TargetUseragent>Mozilla/5.0 (Windows NT 6.1) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.694.0 Safari/534.24</TargetUseragent><UserAgent>Mozilla/5.0 (Windows NT 6.1) AppleWebKit/534.   (KHTML, like Gecko  Chrome/11         Safari/534</UserAgent><Values xmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays"><d2p1:KeyValueOfstringArrayOfstringty7Ep6D1><d2p1:Key>IsMobile</d2p1:Key><d2p1:Value><d2p1:string>False</d2p1:string></d2p1:Value></d2p1:KeyValueOfstringArrayOfstringty7Ep6D1><d2p1:KeyValueOfstringArrayOfstringty7Ep6D1><d2p1:Key>IsTablet</d2p1:Key><d2p1:Value><d2p1:string>False</d2p1:string></d2p1:Value></d2p1:KeyValueOfstringArrayOfstringty7Ep6D1></Values></Match> ---> System.Runtime.Serialization.SerializationException: There was an error deserializing the object of type FiftyOneDegreesCloud.Match. Encountered unexpected character &#39;<&#39;. ---> System.Xml.XmlException: Encountered unexpected character &#39;<&#39;.     at System.Xml.XmlExceptionHelper.ThrowXmlException(XmlDictionaryReader reader, XmlException exception)     at System.Runtime.Serialization.Json.XmlJsonReader.ReadAttributes()     at System.Runtime.Serialization.Json.XmlJsonReader.Read()     at System.Xml.XmlBaseReader.IsStartElement()     at System.Xml.XmlBaseReader.IsStartElement(XmlDictionaryString localName, XmlDictionaryString namespaceUri)     at System.Runtime.Serialization.Json.DataContractJsonSerializer.InternalIsStartObject(XmlReaderDelegator reader)     at System.Runtime.Serialization.Json.DataContractJsonSerializer.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName)     at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)     --- End of inner exception stack trace ---     at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)     at System.Runtime.Serialization.Json.DataContractJsonSerializer.ReadObject(XmlDictionaryReader reader)     at FiftyOneDegreesCloud.FiftyOneDegreesCloudClient.GetMatch(String HtmlEncodedUserAgent, NameValueCollection headers)     --- End of inner exception stack trace ---     at FiftyOneDegreesCloud.FiftyOneDegreesCloudClient.GetMatch(String HtmlEncodedUserAgent, NameValueCollection headers)     at meyerreweb.SiteVersionSelector.SetNewSiteVersionCookie()
    
    System.Exception: Error deserializing response stream:   <Match xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/DetectorRole.Models"><DataSetName>Basic</DataSetName><DetectionTime>0</DetectionTime><Difference>0</Difference><Method>Exact</Method><ProfileIds xmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays"><d2p1:KeyValueOfintint><d2p1:Key>1</d2p1:Key><d2p1:Value>15364</d2p1:Value></d2p1:KeyValueOfintint><d2p1:KeyValueOfintint><d2p1:Key>2</d2p1:Key><d2p1:Value>17017</d2p1:Value></d2p1:KeyValueOfintint><d2p1:KeyValueOfintint><d2p1:Key>3</d2p1:Key><d2p1:Value>17470</d2p1:Value></d2p1:KeyValueOfintint><d2p1:KeyValueOfintint><d2p1:Key>4</d2p1:Key><d2p1:Value>18092</d2p1:Value></d2p1:KeyValueOfintint></ProfileIds><Published>2016-01-06T00:00:00Z</Published><SignaturesCompared>0</SignaturesCompared><TargetUseragent>Mozilla/5.0 (compatible)</TargetUseragent><UserAgent>Mozilla/5.0 (compatible</UserAgent><Values xmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays"><d2p1:KeyValueOfstringArrayOfstringty7Ep6D1><d2p1:Key>IsMobile</d2p1:Key><d2p1:Value><d2p1:string>False</d2p1:string></d2p1:Value></d2p1:KeyValueOfstringArrayOfstringty7Ep6D1><d2p1:KeyValueOfstringArrayOfstringty7Ep6D1><d2p1:Key>IsTablet</d2p1:Key><d2p1:Value><d2p1:string>False</d2p1:string></d2p1:Value></d2p1:KeyValueOfstringArrayOfstringty7Ep6D1></Values></Match> ---> System.Runtime.Serialization.SerializationException: There was an error deserializing the object of type FiftyOneDegreesCloud.Match. Encountered unexpected character &#39;<&#39;. ---> System.Xml.XmlException: Encountered unexpected character &#39;<&#39;.     at System.Xml.XmlExceptionHelper.ThrowXmlException(XmlDictionaryReader reader, XmlException exception)     at System.Runtime.Serialization.Json.XmlJsonReader.ReadAttributes()     at System.Runtime.Serialization.Json.XmlJsonReader.Read()     at System.Xml.XmlBaseReader.IsStartElement()     at System.Xml.XmlBaseReader.IsStartElement(XmlDictionaryString localName, XmlDictionaryString namespaceUri)     at System.Runtime.Serialization.Json.DataContractJsonSerializer.InternalIsStartObject(XmlReaderDelegator reader)     at System.Runtime.Serialization.Json.DataContractJsonSerializer.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName)     at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)     --- End of inner exception stack trace ---     at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)     at System.Runtime.Serialization.Json.DataContractJsonSerializer.ReadObject(XmlDictionaryReader reader)     at FiftyOneDegreesCloud.FiftyOneDegreesCloudClient.GetMatch(String HtmlEncodedUserAgent, NameValueCollection headers)     --- End of inner exception stack trace ---     at FiftyOneDegreesCloud.FiftyOneDegreesCloudClient.GetMatch(String HtmlEncodedUserAgent, NameValueCollection headers)     at meyerreweb.SiteVersionSelector.SetNewSiteVersionCookie()
    
    System.Exception: Error deserializing response stream:   <Match xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/DetectorRole.Models"><DataSetName>Basic</DataSetName><DetectionTime>0</DetectionTime><Difference>0</Difference><Method>Exact</Method><ProfileIds xmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays"><d2p1:KeyValueOfintint><d2p1:Key>1</d2p1:Key><d2p1:Value>15364</d2p1:Value></d2p1:KeyValueOfintint><d2p1:KeyValueOfintint><d2p1:Key>2</d2p1:Key><d2p1:Value>17017</d2p1:Value></d2p1:KeyValueOfintint><d2p1:KeyValueOfintint><d2p1:Key>3</d2p1:Key><d2p1:Value>25390</d2p1:Value></d2p1:KeyValueOfintint><d2p1:KeyValueOfintint><d2p1:Key>4</d2p1:Key><d2p1:Value>19828</d2p1:Value></d2p1:KeyValueOfintint></ProfileIds><Published>2016-01-06T00:00:00Z</Published><SignaturesCompared>0</SignaturesCompared><TargetUseragent>Mozilla/5.0 (TweetmemeBot/4.0; +http://datasift.com/bot.html) Gecko/20100101 Firefox/31.0</TargetUseragent><UserAgent>Mozilla/5.0 (TweetmemeBot/4.0  +http://datasift.com/bot.html                 Firefox/31.0</UserAgent><Values xmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays"><d2p1:KeyValueOfstringArrayOfstringty7Ep6D1><d2p1:Key>IsMobile</d2p1:Key><d2p1:Value><d2p1:string>False</d2p1:string></d2p1:Value></d2p1:KeyValueOfstringArrayOfstringty7Ep6D1><d2p1:KeyValueOfstringArrayOfstringty7Ep6D1><d2p1:Key>IsTablet</d2p1:Key><d2p1:Value><d2p1:string>False</d2p1:string></d2p1:Value></d2p1:KeyValueOfstringArrayOfstringty7Ep6D1></Values></Match> ---> System.Runtime.Serialization.SerializationException: There was an error deserializing the object of type FiftyOneDegreesCloud.Match. Encountered unexpected character &#39;<&#39;. ---> System.Xml.XmlException: Encountered unexpected character &#39;<&#39;.     at System.Xml.XmlExceptionHelper.ThrowXmlException(XmlDictionaryReader reader, XmlException exception)     at System.Runtime.Serialization.Json.XmlJsonReader.ReadAttributes()     at System.Runtime.Serialization.Json.XmlJsonReader.Read()     at System.Xml.XmlBaseReader.IsStartElement()     at System.Xml.XmlBaseReader.IsStartElement(XmlDictionaryString localName, XmlDictionaryString namespaceUri)     at System.Runtime.Serialization.Json.DataContractJsonSerializer.InternalIsStartObject(XmlReaderDelegator reader)     at System.Runtime.Serialization.Json.DataContractJsonSerializer.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName)     at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)     --- End of inner exception stack trace ---     at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)     at System.Runtime.Serialization.Json.DataContractJsonSerializer.ReadObject(XmlDictionaryReader reader)     at FiftyOneDegreesCloud.FiftyOneDegreesCloudClient.GetMatch(String HtmlEncodedUserAgent, NameValueCollection headers)     --- End of inner exception stack trace ---     at FiftyOneDegreesCloud.FiftyOneDegreesCloudClient.GetMatch(String HtmlEncodedUserAgent, NameValueCollection headers)     at meyerreweb.SiteVersionSelector.SetNewSiteVersionCookie()
    
    System.Exception: Error deserializing response stream:   <Match xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/DetectorRole.Models"><DataSetName>Basic</DataSetName><DetectionTime>0</DetectionTime><Difference>0</Difference><Method>Exact</Method><ProfileIds xmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays"><d2p1:KeyValueOfintint><d2p1:Key>1</d2p1:Key><d2p1:Value>17595</d2p1:Value></d2p1:KeyValueOfintint><d2p1:KeyValueOfintint><d2p1:Key>2</d2p1:Key><d2p1:Value>17296</d2p1:Value></d2p1:KeyValueOfintint><d2p1:KeyValueOfintint><d2p1:Key>3</d2p1:Key><d2p1:Value>17317</d2p1:Value></d2p1:KeyValueOfintint><d2p1:KeyValueOfintint><d2p1:Key>4</d2p1:Key><d2p1:Value>18092</d2p1:Value></d2p1:KeyValueOfintint></ProfileIds><Published>2016-01-06T00:00:00Z</Published><SignaturesCompared>0</SignaturesCompared><TargetUseragent>Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; en-us) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1</TargetUseragent><UserAgent>Mozilla/5.0 (Macintosh;    Intel Mac OS X 10_6  ;        AppleWebKit/533.                         Version/5.0   Safari/533</UserAgent><Values xmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays"><d2p1:KeyValueOfstringArrayOfstringty7Ep6D1><d2p1:Key>IsMobile</d2p1:Key><d2p1:Value><d2p1:string>False</d2p1:string></d2p1:Value></d2p1:KeyValueOfstringArrayOfstringty7Ep6D1><d2p1:KeyValueOfstringArrayOfstringty7Ep6D1><d2p1:Key>IsTablet</d2p1:Key><d2p1:Value><d2p1:string>False</d2p1:string></d2p1:Value></d2p1:KeyValueOfstringArrayOfstringty7Ep6D1></Values></Match> ---> System.Runtime.Serialization.SerializationException: There was an error deserializing the object of type FiftyOneDegreesCloud.Match. Encountered unexpected character &#39;<&#39;. ---> System.Xml.XmlException: Encountered unexpected character &#39;<&#39;.     at System.Xml.XmlExceptionHelper.ThrowXmlException(XmlDictionaryReader reader, XmlException exception)     at System.Runtime.Serialization.Json.XmlJsonReader.ReadAttributes()     at System.Runtime.Serialization.Json.XmlJsonReader.Read()     at System.Xml.XmlBaseReader.IsStartElement()     at System.Xml.XmlBaseReader.IsStartElement(XmlDictionaryString localName, XmlDictionaryString namespaceUri)     at System.Runtime.Serialization.Json.DataContractJsonSerializer.InternalIsStartObject(XmlReaderDelegator reader)     at System.Runtime.Serialization.Json.DataContractJsonSerializer.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName)     at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)     --- End of inner exception stack trace ---     at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)     at System.Runtime.Serialization.Json.DataContractJsonSerializer.ReadObject(XmlDictionaryReader reader)     at FiftyOneDegreesCloud.FiftyOneDegreesCloudClient.GetMatch(String HtmlEncodedUserAgent, NameValueCollection headers)     --- End of inner exception stack trace ---     at FiftyOneDegreesCloud.FiftyOneDegreesCloudClient.GetMatch(String HtmlEncodedUserAgent, NameValueCollection headers)     at meyerreweb.SiteVersionSelector.SetNewSiteVersionCookie()
    
    0

    Ben Shillito



    New Member


    Posts:9
    New Member


    --
    22 Jan 2016 09:47 AM
    Could you post a dump of the request header used when accessing the cloud service?
    The problem could well be to do with requested content type.
    0

    VR



    New Member


    Posts:5
    New Member


    --
    22 Jan 2016 02:55 PM
    I tried to reproduce some of these but had no luck, because retrying it would return json as expected. In testing some of these for this reply, I did find one that seems to return the xml consistently. This one seems to do it consistently:

    GET https://cloud.51degrees.com/api/v1/...e+IsTablet HTTP/1.1
    Accept: */*; q=0.5, application/xml
    Accept-Encoding: gzip, deflate
    User-Agent: Ruby
    Host: cloud.51degrees.com

    Here are a couple of others that had the problem one-off (headers only):
    Accept: text/xml,application/xml,application/xhtml xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.2
    Accept-Charset: utf-8,windows-1251;q=0.7,*;q=0.5
    Accept-Encoding: gzip
    Accept-Language: en-us,en;q=0.8
    User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.694.0 Safari/534.24

    Another:
    Accept: text/*,application/xhtml xml,application/xml,application/x-httpd-php
    Range: bytes=0-30720
    User-Agent: Mozilla/5.0 (TweetmemeBot/4.0;
    http://datasift.com/bot.html) Gecko/20100101 Firefox/31.0

    Another:
    Accept: application/xml,application/xhtml xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
    Accept-Charset: utf-8, iso-8859-1, utf-16, *;q=0.7
    Accept-Encoding: gzip
    Accept-Language: en-US
    User-Agent: Mozilla/5.0 (Linux; U; Android 2.3.6; en-us; C5120 Build/GRK39F) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1
    x-wap-profile: http://device.sprintpcs.com/Kyocera/C5120-BST/1.000BT.rdf
    x-network-type: EVDO

    Another:
    Accept: application/xml,application/xhtml xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
    Accept-Charset: utf-8, iso-8859-1, utf-16, *;q=0.7
    Accept-Encoding: gzip
    Accept-Language: en-US
    User-Agent: Mozilla/5.0 (Linux; U; Android 2.3.6; en-us; SAMSUNG-SGH-I717 Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1
    x-wap-profile: http://wap.samsungmobile.com/uaprof/SGH-I717.xml
    x-att-deviceid: SAMSUNG-SGH-I717/I717UCLA1
    0
    You are not authorized to post a reply.