-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathQueryParams.cs
38 lines (33 loc) · 1.04 KB
/
QueryParams.cs
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
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using UnityEngine.Networking;
namespace RESTClient {
public class QueryParams {
private Dictionary<string, string> parameters;
public QueryParams() {
parameters = new Dictionary<string, string>();
}
public void AddParam(string key, string value) {
parameters.Add(key, value);
}
public override string ToString() {
if (parameters.Count == 0) {
return "";
}
StringBuilder sb = new StringBuilder("?");
foreach (KeyValuePair<string, string> param in parameters) {
string key = UnityWebRequest.EscapeURL(param.Key);
string value = UnityWebRequest.EscapeURL(param.Value);
sb.Append(key + "=" + value + "&");
}
sb.Remove(sb.Length - 1, 1);
return sb.ToString();
}
}
}