埋め込み Cookie を必要とする休憩リクエストを作成しようとしています。そのようにSystem.Net参照を使用してそれを行いました
PCL および MVVMCross の System.net への参照
しかし、VS2012でそのPCLライブラリ(System.Net)を移植するのに問題があります。そのコードの実際は、Mac 上の Xamarin Studio で正常に動作します。
その質問を参照して、MVVMCross のネットワーク プラグインをそのように使用しようとしました。
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; });
「要求された機能は実装されていません」というエラーが表示されます。
/Developer/MonoTouch/Source/mono/mcs/class/System/System.Net/HttpWebRequest.cs:553 の System.Net.HttpWebRequest.get_SupportsCookieContainer () [0x00000] で (wrapper remoting-invoke-with-check) システム.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 (Cirrious.MvvmCross.Plugins.Network.Rest.MvxRestClient.BuildHttpRequest で) /Users/stuartlodge/Documents/GitHub/Mvx/MvvmCross/Plugins/Cirrious/Network/Cirrious.MvvmCross.Plugins 内の Plugins.Network.Rest.MvxRestRequest restRequest) [0x00028]。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] /Users 内/stuartlodge/Documents/GitHub/Mvx/MvvmCross/Plugins/Cirrious/Network/Cirrious.MvvmCross.Plugins.Network/Rest/MvxRestClient.cs:20Network.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 /残り/MvxRestClient.cs:20Network.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 /残り/MvxRestClient.cs:20
これは Mac で動作するコードで、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);