Set Cookie for UIWebView requests

前端 未结 5 1747
抹茶落季
抹茶落季 2021-01-05 18:54

I want to embed an UIWebView into my MonoTouch application for an area that is not yet implemented natively.

In order to authenticate with the website I

5条回答
  •  醉梦人生
    2021-01-05 19:29

    Whenever I need to send cookies and params up to the server I use something like RestSharp or Hammock and then pass the response.Content value into UIWebView's loadHtmlString method:

    //setup cookies and params here
    var response = client.Execute(req);
    _webView = new UIWebView();
    _webView.LoadHtmlString(response.Content, new NSUrl(baseUrl));
    

    The NSDictionary API is fairly trivial too:

    var props = new NSMutableDictionary ();
    props.Add (NSHttpCookie.KeyOriginURL, new
    NSString("http://yodawg.com"));
    props.Add (NSHttpCookie.KeyName, new NSString("iherd"));
    props.Add (NSHttpCookie.KeyValue, new NSString("ulikecookies"));
    props.Add (NSHttpCookie.KeyPath, new NSString("/"));
    

提交回复
热议问题