-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathHttpTransferLayer.cs
98 lines (89 loc) · 2.94 KB
/
HttpTransferLayer.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
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using CSHttpBaseLayer;
using CSConfigManager;
using Newtonsoft.Json.Linq;
using System.Windows.Forms;
namespace CSHttpTransferLayer
{
class ListItem
{
public string id;
public string title;
}
class HttpTransferLayer
{
static public List<ListItem> GetList()
{
List<ListItem> list = new List<ListItem>();
string szRet = HttpBaseLayer.Get(ConfigManager.GetDomain() + "index.php/dump/list_show", ConfigManager.GetUserAgent());
//Trace.WriteLine("\n\n" + szRet + "\n\n");
JArray arr = null;
try
{
arr = JArray.Parse(szRet);
foreach (JObject obj in arr)
{
ListItem li = new ListItem();
li.id = obj["id"].ToString();
li.title = obj["title"].ToString();
list.Add(li);
}
}
catch (System.Exception ex)
{
MessageBox.Show(szRet);
}
return list;
}
static public byte[] GetItem(string id)
{
string szRet = HttpBaseLayer.Get(ConfigManager.GetDomain() + "index.php/dump/item_show/" + id, ConfigManager.GetUserAgent());
try
{
return Convert.FromBase64String(szRet);
}
catch (System.Exception ex)
{
MessageBox.Show(szRet);
}
return null;
}
static public bool DelItem(string id, out string ret_tip)
{
string szRet = HttpBaseLayer.Get(ConfigManager.GetDomain() + "index.php/dump/item_del/" + id, ConfigManager.GetUserAgent());
try
{
JObject obj = JObject.Parse(szRet);
ret_tip = obj["ret_tip"].ToString();
return Convert.ToBoolean(obj["ret_flag"]);
}
catch (System.Exception ex)
{
ret_tip = szRet;
}
return false;
}
static public bool AddItem(string title, string content, out string ret_tip)
{
StringBuilder sbParam = new StringBuilder();
sbParam.Append("title=" + HttpUtility.UrlEncode(title));
sbParam.Append("&content=" + HttpUtility.UrlEncode(content));
string szRet = HttpBaseLayer.Post(ConfigManager.GetDomain() + "index.php/dump/item_add", sbParam.ToString(), ConfigManager.GetUserAgent());
try
{
JObject obj = JObject.Parse(szRet);
ret_tip = obj["ret_tip"].ToString();
return Convert.ToBoolean(obj["ret_flag"]);
}
catch (System.Exception ex)
{
ret_tip = szRet;
}
return false;
}
}
}