Skip to content

Commit f19db15

Browse files
committed
initial commit
0 parents  commit f19db15

40 files changed

+2271
-0
lines changed

.gitignore

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
### https://raw.github.com/github/gitignore/967cd6479319efde70a6fa44fa1bfa02020f2357/Unity.gitignore
2+
3+
[Ll]ibrary/
4+
[Tt]emp/
5+
[Oo]bj/
6+
[Bb]uild/
7+
[Bb]uilds/
8+
Assets/AssetStoreTools*
9+
10+
# Visual Studio cache directory
11+
.vs/
12+
13+
# Autogenerated VS/MD/Consulo solution and project files
14+
ExportedObj/
15+
.consulo/
16+
*.csproj
17+
*.unityproj
18+
*.sln
19+
*.suo
20+
*.tmp
21+
*.user
22+
*.userprefs
23+
*.pidb
24+
*.booproj
25+
*.svd
26+
*.pdb
27+
*.opendb
28+
29+
# Unity3D generated meta files
30+
*.pidb.meta
31+
*.pdb.meta
32+
33+
# Unity3D Generated File On Crash Reports
34+
sysinfo.txt
35+
36+
# Builds
37+
*.apk
38+
*.unitypackage
39+
40+
# Rider
41+
.idea/
42+
Assets/Plugins/Editor/JetBrains/
43+
Assets/Plugins/Editor/JetBrains.meta
44+

Assets/Plugins.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Plugins/Editor.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Plugins/Editor/.gitkeep

Whitespace-only changes.

Assets/Plugins/WebRequestUtils.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Plugins/WebRequestUtils/Scripts.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System.Collections.Generic;
2+
using UnityEngine.Networking;
3+
4+
namespace WebRequestUtils
5+
{
6+
public class CookieStore
7+
{
8+
private readonly Dictionary<string, string> _cookieDic = new Dictionary<string, string>();
9+
10+
public IReadOnlyDictionary<string, string> Dic => _cookieDic;
11+
12+
public CookieStore()
13+
{
14+
}
15+
16+
public CookieStore(IEnumerable<KeyValuePair<string, string>> keyValues)
17+
{
18+
foreach (var kv in keyValues)
19+
{
20+
_cookieDic[kv.Key] = kv.Value;
21+
}
22+
}
23+
24+
public void SetUpCookie(UnityWebRequest req)
25+
{
26+
req.SetCookies(_cookieDic);
27+
}
28+
29+
public void Reserve(UnityWebRequest req)
30+
{
31+
if (!req.IsSuccess())
32+
{
33+
return;
34+
}
35+
36+
foreach (var kv in SetCookieParser.Parse(req))
37+
{
38+
_cookieDic[kv.Key] = kv.Value;
39+
}
40+
}
41+
}
42+
}

Assets/Plugins/WebRequestUtils/Scripts/CookieStore.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
using System;
2+
using System.Text;
3+
using UnityEngine;
4+
using UnityEngine.Networking;
5+
6+
namespace WebRequestUtils
7+
{
8+
// using JsonUtility
9+
public static class JsonRequest
10+
{
11+
public static UnityWebRequest Get(string url)
12+
{
13+
return UnityWebRequest.Get(url);
14+
}
15+
16+
public static UnityWebRequest Get(Uri uri)
17+
{
18+
return UnityWebRequest.Get(uri);
19+
}
20+
21+
public static UnityWebRequest Delete(string url)
22+
{
23+
return UnityWebRequest.Delete(url);
24+
}
25+
26+
public static UnityWebRequest Delete(Uri uri)
27+
{
28+
return UnityWebRequest.Delete(uri);
29+
}
30+
31+
public static UnityWebRequest Head(string url)
32+
{
33+
return UnityWebRequest.Head(url);
34+
}
35+
36+
public static UnityWebRequest Head(Uri uri)
37+
{
38+
return UnityWebRequest.Head(uri);
39+
}
40+
41+
public static UnityWebRequest Post<T>(string url, T value)
42+
{
43+
return RequestUpload(UnityWebRequest.kHttpVerbPOST, value)
44+
.SetUrl(url);
45+
}
46+
47+
public static UnityWebRequest Post<T>(Uri uri, T value)
48+
{
49+
return RequestUpload( UnityWebRequest.kHttpVerbPOST, value)
50+
.SetUri(uri);
51+
}
52+
53+
public static UnityWebRequest Put<T>(string url, T value)
54+
{
55+
return RequestUpload(UnityWebRequest.kHttpVerbPUT, value)
56+
.SetUrl(url);
57+
}
58+
59+
public static UnityWebRequest Put<T>(Uri uri, T value)
60+
{
61+
return RequestUpload(UnityWebRequest.kHttpVerbPUT, value)
62+
.SetUri(uri);
63+
}
64+
65+
private static UnityWebRequest RequestUpload<T>(string method, T value)
66+
{
67+
var json = JsonUtility.ToJson(value);
68+
var bytes = Encoding.UTF8.GetBytes(json);
69+
return new UnityWebRequest
70+
{
71+
method = method,
72+
downloadHandler = new DownloadHandlerBuffer(),
73+
uploadHandler = new UploadHandlerRaw(bytes)
74+
}.SetContentTypeJsonHeader();
75+
}
76+
}
77+
}

Assets/Plugins/WebRequestUtils/Scripts/JsonWebRequest.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)