4

I am trying to add a cookie to a request using RestSharp but in fiddler2 I don't see the cookie in the request and service call is failing. Is there some trick to adding a cookie to the RestRequest?

 RestRequest rq = new RestRequest(LTV.NowNext(), Method.GET);
        rc.AddDefaultParameter(LTV.cookie.Key, LTV.cookie.Value, ParameterType.Cookie);

        rc.ExecuteAsync<LTV.nowNext>(rq, (response2) =>
        {
            if (response2.Data == null)
                return;
            foreach (LTV.channel channel in response2.Data.channels)
                this.Items.Add(new ItemViewModel() { LineOne = channel.name, LineTwo = channel.showing[0].content[0].parent.title, LineThree = channel.showing[1].content[0].parent.title });
        });

Thanks, Al

Todd Main
  • 28,951
  • 11
  • 82
  • 146
albal
  • 237
  • 1
  • 3
  • 19
  • Is this the same as http://stackoverflow.com/questions/6557058/unable-to-send-cookies-with-restsharp-on-windows-phone? – Chris Koenig Aug 24 '11 at 00:28
  • Hmm, I've tested AddDefaultParameter and AddParameter and it works fine in fiddler. What is LTV.NowNext() vs LTV.nowNext? – Derek Beattie Jan 14 '12 at 15:22
  • LTV.NowNext() is the URI path and LTV.nowNext is the resultant object - basically my bad and unimaginative naming structure – albal Apr 25 '12 at 08:38

1 Answers1

1

RestSharp has a bug on Windows Phone when adding cookies to the RestRequest!

I solved the issue and have a pull request waiting for them to integrate to the main branch.

For now, you can overcome this issue by using AddHeader("Cookie", cookieValuesString)...

Pedro Lamas
  • 7,185
  • 4
  • 27
  • 35