-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHTTPUnity.cs
More file actions
84 lines (72 loc) · 2.02 KB
/
Copy pathHTTPUnity.cs
File metadata and controls
84 lines (72 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
*┌──────────────────────────────────┐
*│ Copyright(C) 2017 by Antiphon.All rights reserved. │
*│ Author:by Locke Xie 2017-01-13 │
*└──────────────────────────────────┘
*
* 功 能:
* 类 名: HTTPUnity.cs
*
* 修改历史:
*
*
*/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HTTPUnity
{
//POST请求
public IEnumerator POST(string url, Dictionary<string, string> post)
{
WWWForm form = new WWWForm();
foreach(KeyValuePair<string, string> post_arg in post)
{
form.AddField(post_arg.Key, post_arg.Value);
}
WWW www = new WWW(url, form);
yield return www;
if(www.error != null)
{
//POST请求失败
Debug.Log("error is :" + www.error);
} else
{
//POST请求成功
Debug.Log("request ok : " + www.text);
}
}
//GET请求
public IEnumerator GET(string url)
{
WWW www = new WWW(url);
yield return www;
if(www.error != null)
{
//GET请求失败
Debug.Log("error is :" + www.error);
} else
{
//GET请求成功
Debug.Log("request ok : " + www.text);
}
}
//转byte流
public IEnumerator PostBit(string url,string Data)
{
WWWForm wwwForm = new WWWForm();
byte[] byteStream = System.Text.Encoding.Default.GetBytes(Data);
wwwForm.AddBinaryData("post", byteStream);
WWW www = new WWW(url, wwwForm);
yield return www;
if(www.error != null)
{
//POST请求失败
Debug.Log("error is :" + www.error);
} else
{
//POST请求成功
Debug.Log("request ok : " + www.text);
}
}
}