English 中文(简体)
如何在 Java 中提交具有生成值的隐藏 csrf_token_login 字段的 html logon 格式
原标题:How in Java to submit html logon form that has hidden csrf_token_login field with generated value

我要自动从网站下载文件 。 文件下载按钮只在登录后才会出现, 用户名和密码是为此提供的 。 在登录形式上, 还有两个隐藏的字段, 其中之一是 csrf_token_login, 其生成值 :

<input type="hidden" name="csrf_token_login" value="nl9YERDFpecfITb8QwFWneoaefykxp2b" />

使用 java. net. HtpUrlconnection) 如何在 Java (使用 java. net. HtpUrlcomnction) 中编码这一点是很清楚的, 如果我只是登录和密码( 在 < href=" https://stackoverflow.com/ questionss/2793150/how-to-use-java-net- net- url connection- to-fire- handle- http- requests" ) : using java. net. net. net. URLoncomnction to fire和处理 HTTP 请求 < / a > : 提交 POST 请求, 获取 cookies 并设置这些请求以备后续请求, 。 但我如何在 login 格式上取得 csrf_token_login 生成的价值, 并与其他值一起提交?

在登录页面的 Httpurconnection 上, 使用 GetInputStream () 来读取它, 它给了我 csrf 值。 但与此同时, 它可以建立连接, 并且防止为发布数据设置连接属性 :

private HttpURLConnection logUrlCon;
... 
BufferedReader logInput = new BufferedReader(new InputStreamReader(logUrlCon.getInputStream())); 
... // read and get csrf value OK

logUrlCon.setDoOutput(true); // throws java.lang.IllegalStateException: Already connected

是否有办法以登录形式生成 csrf_ tiken_login 值, 并用用户名和密码张贴?

问题回答

使用正则表达式读入登录页面内容并提取数据。您隐藏的字段有非常独特的形式( 带有独有的名称等), 完全适合基于正则表达式的数据提取 。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签