1

I'm tring to make a rest request that require an embedded cookie. I've do that using System.Net reference in that way

Reference to System.net on PCL and MVVMCross

but i've problem to port that PCL library (System.Net) on VS2012. That code infact works fine on Xamarin Studio on Mac.

Referred to that question i've tried to use Network Plugin of MVVMCross in that way:

var url = "http://api.myaddress.com/api";
var json = new Cirrious.MvvmCross.Plugins.Json.MvxJsonConverter();
var client = new Cirrious.MvvmCross.Plugins.Network.Rest.MvxJsonRestClient
{
JsonConverterProvider = () => json
};
var request = new MvxRestRequest(url);
MvxDecodedRestResponse<SearchItem> theResponse = null;
    Exception exception = null;
CookieCollection cc = new CookieCollection ();
cc.Add(new Cookie("mycookiename","mycookievalue","/","api.myaddress.com"));

request.CookieContainer = new CookieContainer();

request.CookieContainer.Add(cc);
client.MakeRequestFor<SearchItem>(request,
                                                    (result) => { theResponse = result; },
                                                (error) => { exception = error; });

I've this error "The requested feature is not implemented."

at System.Net.HttpWebRequest.get_SupportsCookieContainer () [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/System/System.Net/HttpWebRequest.cs:553 at (wrapper remoting-invoke-with-check) System.Net.HttpWebRequest:get_SupportsCookieContainer () at Cirrious.MvvmCross.Plugins.Network.Rest.MvxRestClient.SetCookieContainer (Cirrious.MvvmCross.Plugins.Network.Rest.MvxRestRequest restRequest, System.Net.HttpWebRequest httpRequest) [0x00000] in /Users/stuartlodge/Documents/GitHub/Mvx/MvvmCross/Plugins/Cirrious/Network/Cirrious.MvvmCross.Plugins.Network/Rest/MvxRestClient.cs:128 at Cirrious.MvvmCross.Plugins.Network.Rest.MvxRestClient.BuildHttpRequest (Cirrious.MvvmCross.Plugins.Network.Rest.MvxRestRequest restRequest) [0x00028] in /Users/stuartlodge/Documents/GitHub/Mvx/MvvmCross/Plugins/Cirrious/Network/Cirrious.MvvmCross.Plugins.Network/Rest/MvxRestClient.cs:100 at Cirrious.MvvmCross.Plugins.Network.Rest.MvxRestClient+c__AnonStorey2.<>m__4 () [0x0000d] in /Users/stuartlodge/Documents/GitHub/Mvx/MvvmCross/Plugins/Cirrious/Network/Cirrious.MvvmCross.Plugins.Network/Rest/MvxRestClient.cs:60 at Cirrious.MvvmCross.Plugins.Network.Rest.MvxRestClient.TryCatch (System.Action toTry, System.Action`1 errorAction) [0x00000] in /Users/stuartlodge/Documents/GitHub/Mvx/MvvmCross/Plugins/Cirrious/Network/Cirrious.MvvmCross.Plugins.Network/Rest/MvxRestClient.cs:20

That is the code that works on Mac and that i'd like to port using MvvMCross Network Plugin

HttpWebRequest request = WebRequest.Create("http://api.myaddress.com/api") as HttpWebRequest;  
        request.Method = "GET";
        request.Accept = "application/json";
        request.Headers.Add(HttpRequestHeader.Cookie, "mycookievalue");

        // Get response  

        using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) {  
            // Get the response stream  
            StreamReader reader = new StreamReader (response.GetResponseStream());  
            content = reader.ReadToEnd();

        }

        SearchItem itemssr = jsonConvert.DeserializeObject<SearchItem>(content);
1
  • 2
    One side issue - calling var client = new Cirrious.MvvmCross.Plugins.Network.Rest.MvxJsonRestClient is not portable - use IoC instead - e.g. Mvx.Resolve<IMvxJsonRestClient>() - that way you can get a different implementation on different platforms if you need to.
    – Stuart
    Commented May 25, 2013 at 15:22

1 Answer 1

1

That particular part of the Network plugin is currently under development - see GitHub Issue for REST plugin

It looks as though the cookie feature isn't going to work on the platform you are testing (which I guess from the stacktrace is xamarin.ios)

In this one case, this might be down to temporary issues in Xamarin.iOS - see:


More generally for Plugin development, where a feature doesn't work, then whoever is writing the plugin will have to either override that functionality on that particular platform or will have to mark that feature is NotImplemented on that platform.

Note that marking features as not implemented is perfectly normal - there are always somethings that will not be implemented on some platforms.

Assuming the feature can be implemented then whoever is contributing to the network plugin might:

If this isn't a temporary Xamarin.iOS issue, then I expect that someone will add cookie support in this way at some point soon. If you want that support sooner, then:

  • ask on the GitHub issue, giving the contributors a use case (someone might prioritise it)
  • contribute the code yourself

If working with this existing Network plugin is too large an initial leap, then maybe start by looking at a simpler plugin - see the much simpler Vibrate example in https://speakerdeck.com/cirrious/plugins-in-mvvmcross


If you don't want to mess around with plugins, then just find some other way of moving forwards - e.g. using your own native non-PCL library for that part of the functionality.


Side note:

That code infact works fine on Xamarin Studio on Mac.

As I tried to explain in the other question, currently XS has 'fake' PCL support - so PCLs built in XS are just normal assemblies and are not portable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.