修改json参数请求接口 删除冗余
This commit is contained in:
parent
79e190c58b
commit
bec7858e5c
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 33805700c367ede48908889e8492c787
|
@ -17,7 +17,8 @@ namespace GameLogic
|
||||
{
|
||||
return projectData;
|
||||
}
|
||||
var jsonData = await HttpHandleTool.UnityWebRequestPostJsonByUserCode(page, userCode);
|
||||
string jsonParm = $"{{\"userCode\":\"{userCode}\"}}";
|
||||
var jsonData = await JsonHttpUtility.UnityWebRequestPostJsonByUserCode(page, jsonParm);
|
||||
var projectConfigRoot = JsonUtility.FromJson<ProjectConfigRoot>(jsonData);
|
||||
|
||||
return GetProjectData(projectConfigRoot.data,userCode);
|
||||
@ -29,12 +30,15 @@ namespace GameLogic
|
||||
{
|
||||
return projectData;
|
||||
}
|
||||
var jsonData = await HttpHandleTool.UnityWebRequestPostJsonByUserCode(page, userCode);
|
||||
string jsonParm = $"{{\"userCode\":\"{userCode}\"}}";
|
||||
var jsonData = await JsonHttpUtility.UnityWebRequestPostJsonByUserCode(page, jsonParm);
|
||||
var projectConfigRoot = JsonUtility.FromJson<ProjectConfigRoot>(jsonData);
|
||||
|
||||
return GetProjectData(projectConfigRoot.data,userCode);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#region 场景数据
|
||||
|
||||
public ProjectData GetProjectData(string company = null)
|
||||
|
@ -0,0 +1,43 @@
|
||||
|
||||
using System.Text;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
public static class JsonHttpUtility
|
||||
{
|
||||
|
||||
|
||||
|
||||
public static async UniTask<string> UnityWebRequestPostJsonByUserCode(string page, string data)
|
||||
{
|
||||
string url = $"https://www.arsnowslide.com/brounche/brochure/project/selAllProjectsOnWxByPage/{page}";
|
||||
using (UnityWebRequest request = new UnityWebRequest(url, "POST"))
|
||||
{
|
||||
// 手动构建 JSON 字符串
|
||||
string jsonData = data;
|
||||
byte[] bodyRaw = Encoding.UTF8.GetBytes(jsonData);
|
||||
request.uploadHandler = new UploadHandlerRaw(bodyRaw);
|
||||
request.downloadHandler = new DownloadHandlerBuffer();
|
||||
request.SetRequestHeader("Content-Type", "application/json");
|
||||
|
||||
await request.SendWebRequest().ToUniTask();
|
||||
|
||||
if (request.result == UnityWebRequest.Result.Success)
|
||||
{
|
||||
return request.downloadHandler.text;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"POST Request failed: {request.error}");
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f5f8458a222147e44880cc6c73beccc5
|
@ -341,58 +341,7 @@ namespace GameLogic
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static async UniTask<string> UnityWebRequestPostJsonByUserCode(string url, string userCode,string page= "")
|
||||
{
|
||||
using (UnityWebRequest request = new UnityWebRequest(url, "POST"))
|
||||
{
|
||||
// 手动构建 JSON 字符串
|
||||
string jsonData = $"{{\"userCode\":\"{userCode}\"}}";
|
||||
byte[] bodyRaw = Encoding.UTF8.GetBytes(jsonData);
|
||||
request.uploadHandler = new UploadHandlerRaw(bodyRaw);
|
||||
request.downloadHandler = new DownloadHandlerBuffer();
|
||||
request.SetRequestHeader("Content-Type", "application/json");
|
||||
|
||||
await request.SendWebRequest().ToUniTask();
|
||||
|
||||
if (request.result == UnityWebRequest.Result.Success)
|
||||
{
|
||||
return request.downloadHandler.text;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"POST Request failed: {request.error}");
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
public static async UniTask<string> UnityWebRequestPostJsonByUserCode(string page, string userCode)
|
||||
{
|
||||
string url = $"https://www.arsnowslide.com/brounche/brochure/project/selAllProjectsOnWxByPage/{page}";
|
||||
using (UnityWebRequest request = new UnityWebRequest(url, "POST"))
|
||||
{
|
||||
// 手动构建 JSON 字符串
|
||||
string jsonData = $"{{\"userCode\":\"{userCode}\"}}";
|
||||
byte[] bodyRaw = Encoding.UTF8.GetBytes(jsonData);
|
||||
request.uploadHandler = new UploadHandlerRaw(bodyRaw);
|
||||
request.downloadHandler = new DownloadHandlerBuffer();
|
||||
request.SetRequestHeader("Content-Type", "application/json");
|
||||
|
||||
await request.SendWebRequest().ToUniTask();
|
||||
|
||||
if (request.result == UnityWebRequest.Result.Success)
|
||||
{
|
||||
return request.downloadHandler.text;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"POST Request failed: {request.error}");
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user