C# 模拟页面登录
2024-09-04 07:35:36
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);
} }
}
最新文章
- ANDROID STDUIO 项目里的R文件突然丢失的解决办法N种之一
- 修改eclipse的自动完成功能
- HTML标签的嵌套
- DBMS_JOBS
- .NET/C# 使用Stopwatch测量运行时间
- <;转>;梳理:提高前端性能方面的处理以及不足
- BZOJ 3997 [TJOI 2015 组合数学] 解题报告
- Nodejs in Visual Studio Code 11.前端工程优化
- html5 audio play()方法部分ios机不能播放声音
- 关于python中的operator.itemgetter()函数的用法
- [深度应用]&#183;实战掌握Dlib人脸识别开发教程
- 在编写Arcgis Engine 过程中对于接口引用和实现过程过产生的感悟
- Geomystery现已上架!
- CentOS7设置固定IP
- JS实现clone()方法,对五种主要数据类型进行值复制
- ES6笔记
- java内部类和异常类的概念
- apache 中 RewriteCond 介绍
- Beta冲刺阶段3.0
- .net类中静态方法的继承
热门文章
- AC自动机及其模板
- 3D Computer Grapihcs Using OpenGL - 01 环境设置
- 北风设计模式课程---接口分离原则(Interface Segregation Principle)
- Laravel 的Artisan 命令学习
- Cannot read property 'type' of undefined ....
- MyISAM、InnoDB、Memory这3个常用引擎支持的索引类型
- Bash is an sh-compatible command language interpreter that executes commands read from the standard input or from a file.
- delphi SetWindowPos改变窗体位置和状态
- 类Thread
- JAVA在页面查看或下载服务器上的日志