Skip to content

Commit ee6aa0c

Browse files
committed
Add HTTP demo under API_V2
1 parent b1fea2e commit ee6aa0c

File tree

8 files changed

+144
-2
lines changed

8 files changed

+144
-2
lines changed

Diff for: Demo/API_V2/Assets/API/Network/NetworkSO.asset

+1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ MonoBehaviour:
1818
- {fileID: 11400000, guid: 8fb54c5918d454eea90d5147f2c316ea, type: 2}
1919
- {fileID: 11400000, guid: 1e0539509d074443f92d17035efbe40f, type: 2}
2020
- {fileID: 11400000, guid: cdc97aef7249c4216ac09d2321ce8e83, type: 2}
21+
- {fileID: 11400000, guid: 529e27dae48c91748a3fc5f65603e605, type: 2}
2122
- {fileID: 11400000, guid: 8bae636d6ff994bbfba56ae723a63862, type: 2}

Diff for: Demo/API_V2/Assets/API/Network/TCPSocket/TCPSocket.cs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using LitJson;
44
using UnityEngine;
55
using WeChatWASM;
6+
67
public class TCPSocket : Details
78
{
89
private WXTCPSocket _tcpSocket;

Diff for: Demo/API_V2/Assets/API/Network/UnityWebRequest.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!114 &11400000
4+
MonoBehaviour:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
m_GameObject: {fileID: 0}
10+
m_Enabled: 1
11+
m_EditorHideFlags: 0
12+
m_Script: {fileID: 11500000, guid: fb48e4613a53bb941a20036d7c08fefb, type: 3}
13+
m_Name: WebRequest SO
14+
m_EditorClassIdentifier:
15+
entryScriptTypeName: WebRequest
16+
entryName: "HTTP \u901A\u4FE1"
17+
entryAPI: UnityWebRequest
18+
entryDescription:
19+
optionList: []
20+
initialButtonText: Put
21+
extraButtonList:
22+
- buttonText: Post
23+
- buttonText: Get
24+
initialResultList: []

Diff for: Demo/API_V2/Assets/API/Network/UnityWebRequest/WebRequest SO.asset.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using LitJson;
4+
using UnityEngine;
5+
using UnityEngine.Networking;
6+
using System.Collections;
7+
using WeChatWASM;
8+
9+
public class WebRequest : Details
10+
{
11+
// Start is called before the first frame update
12+
void Start()
13+
{
14+
GameManager.Instance.detailsController.BindExtraButtonAction(0, testPost);
15+
GameManager.Instance.detailsController.BindExtraButtonAction(1, testGet);
16+
}
17+
18+
// 测试API
19+
protected override void TestAPI(string[] args)
20+
{
21+
testPut();
22+
}
23+
24+
private void testGet()
25+
{
26+
StartCoroutine(Get());
27+
}
28+
29+
private void testPost()
30+
{
31+
StartCoroutine(Post());
32+
}
33+
34+
private void testPut()
35+
{
36+
StartCoroutine(Put());
37+
}
38+
39+
IEnumerator Get()
40+
{
41+
UnityWebRequest webRequest = UnityWebRequest.Get("https://postman-echo.com/get");
42+
43+
yield return webRequest.SendWebRequest();
44+
45+
if (webRequest.isHttpError || webRequest.isNetworkError)
46+
Debug.Log(webRequest.error);
47+
else
48+
{
49+
Debug.Log("get complete: " + webRequest.downloadHandler.text);
50+
}
51+
52+
}
53+
54+
IEnumerator Post()
55+
{
56+
WWWForm form = new WWWForm();
57+
//键值对
58+
form.AddField("key", "value");
59+
form.AddField("name", "mafanwei");
60+
form.AddField("blog", "qwe25878");
61+
62+
UnityWebRequest webRequest = UnityWebRequest.Post("https://postman-echo.com/post", form);
63+
64+
yield return webRequest.SendWebRequest();
65+
66+
if (webRequest.isHttpError || webRequest.isNetworkError)
67+
Debug.Log(webRequest.error);
68+
else
69+
{
70+
Debug.Log("post complete: " + webRequest.downloadHandler.text);
71+
}
72+
}
73+
74+
IEnumerator Put()
75+
{
76+
byte[] myData = System.Text.Encoding.UTF8.GetBytes("This is some test data");
77+
UnityWebRequest www = UnityWebRequest.Put("https://postman-echo.com/put", myData);
78+
yield return www.SendWebRequest();
79+
80+
if (www.result != UnityWebRequest.Result.Success)
81+
{
82+
Debug.Log(www.error);
83+
}
84+
else
85+
{
86+
Debug.Log("Put complete: " + www.downloadHandler.text);
87+
}
88+
}
89+
}

Diff for: Demo/API_V2/Assets/API/Network/UnityWebRequest/WebRequest.cs.meta

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Demo/API_V2/Assets/WX-WASM-SDK-V2/Editor/MiniGameConfig.asset

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ MonoBehaviour:
1313
m_Name: MiniGameConfig
1414
m_EditorClassIdentifier:
1515
ProjectConf:
16-
projectName: GameClubDemo
16+
projectName: HTTPDemo
1717
Appid: wxb7d4485dbc1233ca
1818
CDN:
1919
assetLoadType: 1
2020
compressDataPackage: 0
2121
VideoUrl:
22-
DST: C:/Users/xiaoyuejin/Desktop/finaltest
22+
DST: C:/Users/xiaoyuejin/Desktop/httpTest
2323
StreamCDN:
2424
bundleHashLength: 32
2525
bundlePathIdentifier: StreamingAssets;

0 commit comments

Comments
 (0)