将下载的 .html 重命名为 .zip 然后给出正确的文件,所以我正确地创建了 zip。
如果我将 Edge 设置为提示下载,而不是自动下载文件,那么我可以在下载时将其视为 zip 文件。
项目下载。表示在javase的downloads下下载有关html的文件。
超文本标记语言,标准通用标记语言下的一个应用,超文本就是指页面内可以包含图片,链接,甚至是音乐,程序等非文字元素。 超文本标记语言的结构包括头部分英语是Head,和主体部分Body,其中头部提供关于网页的信息,主体部分提供网页的具体内容。
package org.shawimport org.apache.commons.httpclient.Cookie
import org.apache.commons.httpclient.HttpClient
import org.apache.commons.httpclient.NameValuePair
import org.apache.commons.httpclient.methods.GetMethod
import org.apache.commons.httpclient.methods.PostMethod
public class BaiyouBBS {
static final String LOGON_SITE = "www.qiluyiyou.com"
static final int LOGON_PORT = 80
public Cookie[] login(String name, String pas) {
try {
HttpClient client = new HttpClient()
client.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT)
PostMethod post = new PostMethod("/logging.php?action=login")
client.executeMethod(post)
String responseString = new String(post.getResponseBody(), "gbk")
post.releaseConnection()
String formhash = getFormHash(responseString)
System.out.println(formhash)
post = new PostMethod("/logging.php?action=login&")
NameValuePair[] params = new NameValuePair[11]
params[0] = new NameValuePair("loginfield", "username")
params[1] = new NameValuePair("username", name)
params[2] = new NameValuePair("password", pas)
params[3] = new NameValuePair("referer", "index.php")
params[4] = new NameValuePair("questionid", "0")
params[5] = new NameValuePair("answer", "")
params[6] = new NameValuePair("cookietime", "2592000")
params[7] = new NameValuePair("formhash", formhash)
params[8] = new NameValuePair("loginmode", "")
params[9] = new NameValuePair("loginsubmit", "true")
params[10] = new NameValuePair("styleid", "")
post.setRequestBody(params)
client.executeMethod(post)
// responseString = new String(post.getResponseBody(), "gbk")
post.releaseConnection()
GetMethod get = new GetMethod("/index.php")
client.executeMethod(get)
responseString = new String(get.getResponseBody(), "gbk")
get.releaseConnection()
System.out.println(responseString)
} catch (Exception e) {
e.printStackTrace()
}
return null
}
public String getFormHash(String htmlContent) {
try {
int start = htmlContent.indexOf("name=\"formhash\"")
start = htmlContent.indexOf("value=\"", start) + 7
int end = htmlContent.indexOf("\"", start)
String formhash = htmlContent.substring(start, end)
return formhash
} catch (RuntimeException e) {
throw e
}
}
public static void main(String[] args) {
new BaiyouBBS().login("zzzxxxzzz", "zzzxxxzzz")
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)