using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks; namespace WebSiteLogin
{
public class LoginOP
{
public void Login()
{
CookieContainer cc = new CookieContainer(); Console.WriteLine("请输入你的用户名:");
string userName = Console.ReadLine();
Console.WriteLine("请输入你的密码:");
string password = Console.ReadLine(); string postData = string.Format("UserName={0}&Password={1}", userName, password);
byte[] byteArray = Encoding.UTF8.GetBytes(postData); // 转化 HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(new Uri("http://localhost:10476/home/ApplyLogin"));
webRequest.CookieContainer = cc;
webRequest.Method = "POST";
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.ContentLength = byteArray.Length;
Stream newStream = webRequest.GetRequestStream();
// Send the data.
newStream.Write(byteArray, , byteArray.Length); //写入参数
newStream.Close(); HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
string text = sr.ReadToEnd();
Console.WriteLine(text); Console.WriteLine("-------------------------------------------------------------");
Console.WriteLine("返回结果:");
Console.WriteLine("-------------------------------------------------------------"); HttpWebRequest webRequest2 = (HttpWebRequest)WebRequest.Create(new Uri("http://localhost:10476/home/AuthenticationPage"));
webRequest2.CookieContainer = cc;
HttpWebResponse response2 = (HttpWebResponse)webRequest2.GetResponse();
StreamReader sr2 = new StreamReader(response2.GetResponseStream(), Encoding.UTF8);
string text2 = sr2.ReadToEnd();
Console.WriteLine(text2);
} }
}

最新文章

  1. ANDROID STDUIO 项目里的R文件突然丢失的解决办法N种之一
  2. 修改eclipse的自动完成功能
  3. HTML标签的嵌套
  4. DBMS_JOBS
  5. .NET/C# 使用Stopwatch测量运行时间
  6. <转>梳理:提高前端性能方面的处理以及不足
  7. BZOJ 3997 [TJOI 2015 组合数学] 解题报告
  8. Nodejs in Visual Studio Code 11.前端工程优化
  9. html5 audio play()方法部分ios机不能播放声音
  10. 关于python中的operator.itemgetter()函数的用法
  11. [深度应用]·实战掌握Dlib人脸识别开发教程
  12. 在编写Arcgis Engine 过程中对于接口引用和实现过程过产生的感悟
  13. Geomystery现已上架!
  14. CentOS7设置固定IP
  15. JS实现clone()方法,对五种主要数据类型进行值复制
  16. ES6笔记
  17. java内部类和异常类的概念
  18. apache 中 RewriteCond 介绍
  19. Beta冲刺阶段3.0
  20. .net类中静态方法的继承

热门文章

  1. AC自动机及其模板
  2. 3D Computer Grapihcs Using OpenGL - 01 环境设置
  3. 北风设计模式课程---接口分离原则(Interface Segregation Principle)
  4. Laravel 的Artisan 命令学习
  5. Cannot read property 'type' of undefined ....
  6. MyISAM、InnoDB、Memory这3个常用引擎支持的索引类型
  7. Bash is an sh-compatible command language interpreter that executes commands read from the standard input or from a file.
  8. delphi SetWindowPos改变窗体位置和状态
  9. 类Thread
  10. JAVA在页面查看或下载服务器上的日志