c# - 获取 CSRF 令牌以强制登录,但它不返回任何内容 - ArgumentOutOfRangeException:长度不能小于零
问题描述
我正在尝试从大学获取一些课程数据,例如时间和地点。我目前正在尝试获取 CSRF 令牌,然后使用它登录。但是当我尝试使用一些简单的统一按钮获取 htmldata 时,它不会返回任何内容。ArgumentOutOfRangeException:长度不能小于零。参数名称:长度
有人可以帮助我解决潜在的问题吗?并可能指出为什么它不返回任何 html 数据?
谢谢阅读
{
public Text responseText;
public void Button()
{
System.Net.CookieContainer myCookies = new System.Net.CookieContainer();
string mySrc = HttpMethod.Get("https://signon.ruc.dk/login?service=https%3A%2F%2Fmoodle.ruc.dk%2Flogin%2Findex.php", "https://signon.ruc.dk/login?service=https%3A%2F%2Fmoodle.ruc.dk%2Flogin%2Findex.php", ref myCookies);
string token = GetBetween(mySrc, "name=\"execution\" value=\"" , "=\">");
// string username = "XXX";
// string password = "XXX";
string postData = "username=" + "XXX" + "&password=" + "XXX" + "&submit=Sign-on&execution=" + token;
bool result = HttpMethod.Post("https://signon.ruc.dk/login?service=https%3A%2F%2Fmoodle.ruc.dk%2Flogin%2Findex.php", postData, "https://signon.ruc.dk/login?service=https%3A%2F%2Fmoodle.ruc.dk%2Flogin%2Findex.php", myCookies);
if (result)
responseText.text = result.ToString();
else
Debug.Log("Invalid!");
}
static string GetBetween(string msg, string start, string stop)
{
int StartIndex = msg.IndexOf(start) + start.Length;
int StopIndex = msg.IndexOf(stop);
return msg.Substring(StartIndex, StopIndex - StartIndex);```
解决方案
我相信您看到的异常是指出结果StopIndex - StartIndex
小于零。这可能是有道理的,因为没有什么限制对子字符串的搜索在stop
子字符串的末尾之后start
。你是不是想说:
int StopIndex = msg.IndexOf(stop, StartIndex);
推荐阅读
- unity3d - Unity 无法为 android 构建游戏
- c# - 缓存依赖关系,还是在注入时复制它们?
- r - 按行匹配列值与 dplyr 中的差异
- javascript - React 滚动条无法正常工作
- html - 未捕获的类型错误:c._shady_getRootNode 不是函数
- python - Django自定义命令:AttributeError:'Settings'对象没有属性'setmodule'
- reactjs - React Popper 和 React CSStransition
- javascript - 单击照片时向下移动滚动条 (html)
- python - 使用seasonal_decompose 在时间序列分析中检测季节性时出错
- java - ArrayList 的记录器注释