zoukankan      html  css  js  c++  java
  • Xamarin.ios 调用接口

    NSString urlstring = new NSString("http://211.155.229.230:8585/api/users/postregister"); 
                NSMutableUrlRequest request = new NSMutableUrlRequest(new NSUrl(urlstring));
                request.Url = new NSUrl(urlstring);
                request.HttpMethod = "POST"; 

                NSUrlConnection connection = new NSUrlConnection(request, new ConnectionDelegate((response) =>
                    {
                        //解析数据
                        JsonValue jsonObj = JsonValue.Parse(response); 
                    }));
           ////ConnectionDelegate

    using System;
    using Foundation;
    using System.Text;

    namespace XinPeiOA
    {
        public class ConnectionDelegate : NSUrlConnectionDataDelegate
        {
            public ConnectionDelegate()
            {
            }
            private Action<string> finishedCallback;
            private StringBuilder responseData;
            //构造方法
            public ConnectionDelegate(Action<string> callback)
            {
                this.finishedCallback = callback;
                this.responseData = new StringBuilder();
            }
            //结束数据后的相关操作
            public override void ReceivedData(NSUrlConnection connection, NSData data)
            {
                //判断数据是否存储
                if (null != data)
                {
                    this.responseData.Append(data.ToString());
                }
            }
            ///当请求结束后的相关操作
            public override void FinishedLoading(NSUrlConnection connection)
            {
                if (null != this.finishedCallback)
                {
                    this.finishedCallback(this.responseData.ToString());
                }
                this.responseData.Clear();
            }


            //当请求失败时的相关操作
            public override void FailedWithError(NSUrlConnection connection, NSError error)
            {
                //判断是否有错误
                if (null != error)
                {
                    Console.WriteLine("Error in connection! { 0}", error.LocalizedDescription);
                }
            }


        }
    }


  • 相关阅读:
    网络流,再出发!
    2SAT
    并查集
    最大密度子图
    网络流提高专题(洛谷题单)
    JQuery 操作 ListBox间移动和ListBox内移动
    关于多表Update和Delete的应用
    XML格式与DataTable、DataSet、DataView格式的转换
    FCKeditor配置和精简
    点击fileupload后button事件不起作用
  • 原文地址:https://www.cnblogs.com/IKang8701348/p/5762529.html
Copyright © 2011-2022 走看看