using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
namespace MuHua {
///
/// Post请求数据
///
public class DataRequestPost : DataRequest {
public readonly string url;
public readonly string json;
public readonly WWWForm form;
public readonly WebRequestType type;
public Action OnError;
public Action OnCallback;
public override string Url => url;
public override WebRequestType RequestType => type;
public override string Json => json;
public override WWWForm Form => form;
/// Web Post请求 提交json数据
public DataRequestPost(string url, string json, Action OnCallback = null) {
this.url = url;
this.json = json;
this.OnCallback = OnCallback;
type = WebRequestType.PostJson;
}
/// Web Post请求 提交WWWForm数据
public DataRequestPost(string url, WWWForm form, Action OnCallback = null) {
this.url = url;
this.form = form;
this.OnCallback = OnCallback;
type = WebRequestType.PostForm;
}
public override void RequestResultHandle(bool isDone, UnityWebRequest web) {
DownloadHandler downloadHandler = web.downloadHandler;
if (!isDone) { OnError?.Invoke(downloadHandler.text); return; }
OnCallback?.Invoke(downloadHandler.text);
}
}
}