赞
踩
本类库封装基于ulua框架LuaFramework
HttpWebRequest
HttpWebResponse
LuaFramework
HTTPRequest
发起HTTP请求,异步回调返回HTTPResponse
HTTPRequest
源码- using System;
- using System.Net;
- using System.IO;
- using System.Text;
- using System.Collections.Generic;
- using LuaFramework;
- using UnityEngine;
- /// <summary>
- /// Http请求
- /// </summary>
- public class HTTPRequest
- {
- private string url;
- private int timeout;
- private Action<HTTPResponse> callback;
- private HttpWebRequest request;
- private string method;
- private string contentType;
- private KeyValuePair<string, int> proxy;
- protected int range = -1;
- // post内容
- private StringBuilder postBuilder;
- /// <summary>
- /// 错误代码
- /// </summary>
- public const int ERR_EXCEPTION = -1;
- /// <summary>
- /// 构造函数, 构造GET请求
- /// </summary>
- /// <param name="url">url地址</param>
- /// <param name="timeout">超时时间</param>
- /// <param name="callback">回调函数</param>
- public HTTPRequest (string url, string method, int timeout, Action<HTTPResponse> callback)
- {
- this.url = url;
- this.timeout = timeout;
- this.callback = callback;
- this.method = method.ToUpper();
- }
- /// <summary>
- /// 设置Post内容
- /// </summary>
- /// <param name="data">内容</param>
- public void SetPostData(string data) {
- if (postBuilder == null) {
- postBuilder = new StringBuilder (data.Length);
- }
- if (postBuilder.Length > 0) {
- postBu
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。