public static void TestPostHttps() { string loginUrl = "https://42.96.143.36:8443/index"; Encoding encoding = Encoding.GetEncoding("gb2312"); //Encoding encoding = Encoding.GetEncoding("utf8"); IDictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("c", "Courier"); parameters.Add("a", "login"); parameters.Add("courierCode", "1000"); //parameters.Add("cabinetCode", "20140801001"); parameters.Add("cabinetCode", "21"); parameters.Add("datetime", "1408202160"); parameters.Add("token", "2b4109904540e7f1a858a70f99c76dad"); CookieCollection cookies = new CookieCollection();//如何从response.Headers["Set-Cookie"];中获取并设置CookieCollection的代码略 HttpWebResponse response = HttpWebResponseUtility.CreatePostHttpResponse(loginUrl, parameters, null, null, encoding, cookies); string cookieString = response.Headers["Set-Cookie"]; string result = ""; using (StreamReader reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8)) { result = reader.ReadToEnd(); } ServerCallback sc = new ServerCallback(); StringReader sr = new StringReader(result); JsonSerializer serializer = new JsonSerializer(); try { sc = (ServerCallback)serializer.Deserialize(new JsonTextReader(sr), typeof(ServerCallback)); } catch (Exception e) { CLog4net.LogError(e.ToString()); sc = null; } //JsonReader readerjson = new JsonTextReader(new StringReader(result)); //JObject jo = JObject.Parse(result); //string[] values = jo.Properties().Select(item => item.Value.ToString()).ToArray(); //DareneExpressCabinetClient.Service.ServerCallback cb = new DareneExpressCabinetClient.Service.ServerCallback(); //StringReader sr = new StringReader(result); //JsonSerializer serializer = new JsonSerializer(); ////StringReader sr = new StringReader(@"{""Input"":""stone"", ""Output"":""gold""}"); //cb = (DareneExpressCabinetClient.Service.ServerCallback)serializer.Deserialize(new JsonTextReader(sr), typeof(DareneExpressCabinetClient.Service.ServerCallback)); //Console.WriteLine(cb.Success + "=>" + cb.CabinetCode); }
public static void TestGetHttp() { string userName = "******"; //string tagUrl = "http://cang.baidu.com/" + userName + "/tags"; //string tagUrl = "http://localhost:8080/Loom/comm/get.do?id=1"; string tagUrl = "http://localhost:8080/Loom/comm/get.do?id=1"; CookieCollection cookies = new CookieCollection();//如何从response.Headers["Set-Cookie"];中获取并设置CookieCollection的代码略 HttpWebResponse response = HttpWebResponseUtility.CreateGetHttpResponse(tagUrl, null, null, cookies); string result = ""; using (StreamReader reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8)) { result = reader.ReadToEnd(); } JsonReader readerjson = new JsonTextReader(new StringReader(result)); }