public static string HttpGet(string Url, string postDataStr)
{
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url + (postDataStr == "" ? "" : "?") + postDataStr);
request.Method = "GET";
request.ContentType = "text/html;charset=UTF-8";
request.Timeout = 10000;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream myResponseStream = response.GetResponseStream();
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.UTF8);
string retString = myStreamReader.ReadToEnd();
myStreamReader.Close();
myResponseStream.Close();
return retString;
}
catch (Exception)
{
return null;
}
}
public static string HttpGetList(string Url, string token)
{
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
request.Method = "GET";
request.Headers.Add("x-token", token);
request.ContentType = "text/html;charset=UTF-8";
request.Timeout = 10000;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream myResponseStream = response.GetResponseStream();
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.UTF8);
string retString = myStreamReader.ReadToEnd();
myStreamReader.Close();
myResponseStream.Close();
return retString;
}
catch (Exception)
{
return null;
}
}
public static string HttpPost(string Url, string postDataStr)
{
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
request.Method = "POST";
request.Timeout = 6000000;
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = postDataStr.Length;
StreamWriter writer = new StreamWriter(request.GetRequestStream(), Encoding.ASCII);
writer.Write(postDataStr);
writer.Flush();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string encoding = response.ContentEncoding;
if (encoding == null || encoding.Length < 1)
{
encoding = "UTF-8";
}
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(encoding));
string retString = reader.ReadToEnd();
return retString;
}
catch (Exception)
{
return null;
}
}
public static string HttpPostObj(string Url ,string token,string modelName, string model, string color)
{
using (HttpClient client = new HttpClient())
{
try
{
var content = new MultipartFormDataContent();
content.Headers.Add("x-token", token);
content.Add(new StringContent(modelName), "modelName");
content.Add(new ByteArrayContent(File.ReadAllBytes(model)), "model",Path.GetFileName(model));
content.Add(new ByteArrayContent(File.ReadAllBytes(color)), "color", Path.GetFileName(color));
var result = client.PostAsync(Url, content).Result.Content.ReadAsStringAsync().Result;
return result;
}
catch (Exception ex)
{
LogMSG.WriteLogmsg("Http数据上传异常", ex.Message.ToString());
}
}
return null;
}
代码结果解析
class JsonTools
{
public static Dictionary<string, string> LoginJsonTostr(string json)
{
Dictionary<string, string> loginmess = new Dictionary<string, string>();
JObject jo = (JObject)JsonConvert.DeserializeObject(json);
var status = jo["status"] ;
loginmess.Add("status", status.ToString());
var message = jo["message"];
loginmess.Add("message", message.ToString());
if (status.ToString()!="200")
{
return loginmess;
}
var data = jo["data"] as JObject;
var xxx= data["xxx"];
loginmess.Add("xxx", xxx.ToString());
var xxx= data["xxx"];
loginmess.Add("xxx", xxx.ToString());
var xxx= data["xxx"];
loginmess.Add("xxx", xxx.ToString());
var xxx= xxx["xx"];
loginmess.Add("xxxx", xxx.ToString());
var xxx= xxx["xxxx"];
loginmess.Add("xxxxx", xxx.ToString());
var login_count = xxx["xxxxx"];
loginmess.Add("xxxx", xxx.ToString());
var xxx= xxx["xxxx"];
loginmess.Add("xxxxx", xxx.ToString());
var xxx= xxx["xxxx"];
loginmess.Add("xxxx", xxx.ToString());
var xxxx= admin["xxx"];
loginmess.Add("xxxx", xxx.ToString());
var xxxx= admin["xxx"];
loginmess.Add("xxx", xxx.ToString());
var xxx= admin["xxx"];
loginmess.Add("xxx", xxx.ToString());
return loginmess;
}
public static Dictionary<string, string> SendJsonTostr(string json)
{
Dictionary<string, string> Sendmess = new Dictionary<string, string>();
JObject jo = (JObject)JsonConvert.DeserializeObject(json);
var status = jo["status"];
Sendmess.Add("status", status.ToString());
var message = jo["message"];
Sendmess.Add("message", message.ToString());
return Sendmess;
}
public static string JsonTostr(string json)
{
JObject jo = (JObject)JsonConvert.DeserializeObject(json);
var data = jo["data"] as JObject;
string Cont = data["token"].ToString();
return Cont;
}
public static List<mUserUpperlist> upplistJsonTostr(string json)
{
List<mUserUpperlist> mUserUpperlists = new List<mUserUpperlist>();
JObject jo = (JObject)JsonConvert.DeserializeObject(json);
var status = jo["status"];
var message = jo["message"];
if (status.ToString()!="200")
{
mUserUpperlist muserUpperlist = new mUserUpperlist();
muserUpperlist.status = status.ToString();
muserUpperlist.message = message.ToString();
mUserUpperlists.Add(muserUpperlist);
return mUserUpperlists;
}
var data = jo["data"];
var xxx= data["xxx"];
var xxx= data["xxx"];
int len= Convert.ToInt32(count.ToString());
for (int i = 0; i < len-1; i++)
{
mUserUpperlist muserUpperlist = new mUserUpperlist();
muserUpperlist.status = status.ToString();
muserUpperlist.message = message.ToString();
muserUpperlist.count = count.ToString();
var xxx= list[i]["xxx"];
var xxx= list[i]["xxx"];
var xxx= list[i]["xxx"];
var xxx= list[i]["xxx"];
var xxx= list[i]["xxx"];
var xxx= list[i]["xxx"];
var xxx= list[i]["xxxx"];
var xxx= list[i]["xxx"];
muserUpperlist.mlist = new Dictionary<string, string>();
var create_time = list[i]["create_time"];
muserUpperlist.mlist.Add("xxx", xxx.ToString());
muserUpperlist.mlist.Add("xxx", xxx.ToString());
muserUpperlist.mlist.Add("xxx", xxx.ToString());
muserUpperlist.mlist.Add("xxx", xxx.ToString());
muserUpperlist.mlist.Add("xxx", xxx.ToString());
muserUpperlist.mlist.Add("xxx", xxxx.ToString());
muserUpperlist.mlist.Add("xxx", xxx.ToString());
muserUpperlist.mlist.Add("xxx", xxx.ToString());
muserUpperlist.mlist.Add("xxxx", xxxx.ToString());
mUserUpperlists.Add(muserUpperlist);
}
return mUserUpperlists;
}
}
user 类
class mUser
{
public static string account;
public static string password;
public static Dictionary<string, string> loginmess;
public static Dictionary<string, string> Sendmess;
public static List<mUserUpperlist> mUserUpperlists;
}
public struct mUserUpperlist
{
public string status;
public string message;
public string count;
public Dictionary<string, string> mlist;
}
|