• 大小: 209KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-16
  • 语言: 其他
  • 标签: Xamarin  

资源简介

VS2017 下Xamarin移动开发Get,Post服务请求源码封装,支持实体对象直接发送Request请求: var result = HttpClientHelper.GetInstance.PostT("GetStoreTVProductInfo", request); 注意:Json转换使用的Newtonsoft.Json.dll需要使用新版本,我一并放入了压缩包,可直接引用。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Newtonsoft.Json;

namespace MyAndroidSecondTest
{
    /// 
    /// 服务请求帮助类
    /// Author:William(徐威)
    /// Create Time:2018-03-14
    /// 

    public class HttpClientHelper
    {
        //定义默认服务请求Url
        public static string apiUrl = “http://192.168.1.64/Eson.Store.Host/“;

        #region 构造客户端Http操作帮助类静态对象
        private static HttpClientHelper instance = null;

        /// 
        /// Http请求对象
        /// Author:William(徐威)
        /// Create Time:2018-03-14
        /// 

        private static HttpClient client = null;

        private static readonly object convertlock = new object();

        /// 
        /// 客户端Http操作帮助类静态对象
        /// Author:William(徐威)
        /// Create Time:2018-03-14
        /// 

        public static HttpClientHelper GetInstance
        {
            get
            {
                lock (convertlock)
                {
                    if (instance == null)
                    {
                        instance = new HttpClientHelper();
                    }

                    //初始化请求地址
                    client = new HttpClient();
                    return instance;
                }
            }
        }

        /// 
        /// 客户端Http操作帮助类静态对象
        /// Author:William(徐威)
        /// Create Time:2018-03-14
        /// 

        public static HttpClientHelper CreateInstance(string servicesURL = null)
        {
            lock (convertlock)
            {
                if (!string.IsNullOrEmpty(servicesURL))
                {
                    apiUrl = servicesURL;
                }

                if (instance == null)
                {
                    instance = new HttpClientHelper();
                }
                //初始化请求地址
                client = new HttpClient();

                return instance;
            }
        }


        /// 
        /// 对Http请求对象的服务地址重新赋值
        /// Author:William(徐威)
        /// Create Time:2018-03-14
        /// 

        /// 服务地址
        public void BindRestAddress(string restAddress)
        {
            apiUrl = restAddress;
        }

        #region 定义返回方式定义为Json
        /// 
        /// 定义返回方式定义为Json
        /// Author:William(徐威)
        /// Create Time:2018-03-14
        /// 

        /// 
        private void BindUriResopnseType(ref string uri)
        {
            #region 返回方式定义为Json
            if (uri.IndexOf(“?“) == -1)
            {
                uri += “?format=json“;
            

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       8592  2018-03-14 19:36  Xamarin移动开发Get、Post服务请求源码\HttpClientHelper.cs

     文件     658432  2018-02-18 09:41  Xamarin移动开发Get、Post服务请求源码\Newtonsoft.Json.dll

     目录          0  2018-03-14 19:59  Xamarin移动开发Get、Post服务请求源码

----------- ---------  ---------- -----  ----

               667024                    3


评论

共有 条评论