转 winfrom如何通过http来进行通信,并且通过传递json格式的数据可接受json格式的数据
json
适用于现代 C++ 的 JSON。
项目地址:https://gitcode.com/gh_mirrors/js/json
免费下载资源
·
winfrom如何通过http来进行通信,并且通过传递json格式的数据可接受json格式的数据
string username = this.textBox1.Text;
string password = this.textBox2.Text;
string AA = HttpUtility.UrlEncode(username, Encoding.UTF8);
string bb = HttpUtility.UrlEncode(password, Encoding.UTF8);
ASCIIEncoding encoding = new ASCIIEncoding();
String content = "";
try
{
string json = "{\"uname\":\"" + AA + "\",\"psw\":\"" + bb + "\",\"param\":\"login\"}";
MessageBox.Show(json);
JObject o = JObject.Parse(json);
String param = o.ToString();
byte[] data = encoding.GetBytes(param);
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://192.168.10.30:8080/ss/aa.do?method=login");
request.KeepAlive = false;
request.Method = "POST";
request.ContentType = "application/json;characterSet:UTF-8";
request.ContentLength = data.Length;
Stream sm = request.GetRequestStream();
sm.Write(data, 0, data.Length);
sm.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream streamResponse = response.GetResponseStream();
StreamReader streamRead = new StreamReader(streamResponse, Encoding.UTF8);
Char[] readBuff = new Char[256];
int count = streamRead.Read(readBuff, 0, 256);
while (count > 0)
{
String outputData = new String(readBuff, 0, count);
content += outputData;
count = streamRead.Read(readBuff, 0, 256);
}
response.Close();
MessageBox.Show(content);
string jsons = content;
JObject jobject = JObject.Parse(jsons);
JsonReader read = jobject.CreateReader();
MessageBox.Show(read.ToString());
MessageBox.Show(jobject.ToString());
//Dictionary<string, string>[] companies = content.Deserialize<Dictionary<string, string>[]>(content);
//foreach (var item in companies)
//{
// MessageBox.Show(item);
//}
}
catch (Exception ex)
{
}
finally
{
}
GitHub 加速计划 / js / json
41.72 K
6.61 K
下载
适用于现代 C++ 的 JSON。
最近提交(Master分支:1 个月前 )
960b763e
4 个月前
8c391e04
6 个月前
更多推荐
已为社区贡献5条内容
所有评论(0)