当我使用apache下载这个文本文件asdf.txt时:
URL fileURL = new URL(urlMatcher.group(1)); FileUtils.copyURLToFile(fileURL, new File(fileName));
它将生成网页的html代码,而不是
我就是那个文本文件!
它应该会回来。
将url打印为字符串的结果如下:
请帮我找出登录所需的POST请求的Java代码
Host=alm.automic.com 用户代理=Mozilla/5.0(WindowsNT6.1;WOW64;rv:39.0) 接受=text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8 接受-语言=en-US,en;q=0.5 接受-编码=gzip,放气 Referer=https://alm.automic.com/jama/login.req Cookie=JSESSIONID=CA14239217D0E54E913D17083F71724F;DWRSESSIONID=8nCO$BHWFA2282XF4fVYnmwl7Wk;jamaContourServerTime=1436778397165;jamaContourSessionExpiry=1436778397165 连接=保持活力 Content-Type=application/x-www-form-urlencoded 内容长度=53 POSTDATA=j_username=user&j_password=pass&submit=Login
请帮忙,谢谢提前!
发布于 2015-07-14 11:23:18
了解如何进行http连接,如果有人需要的话:使用下面的类和类似脾气数据(Firefox addon)之类的东西来查找GET/POST请求头/数据,并以如下方式将其添加到下面的类中。
ArrayList<String> cookies = new ArrayList<String>(1);
HttpClient httpclient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(link);
// Request parameters and other properties.
List<NameValuePair> params = new ArrayList<NameValuePair>(2);
httpGet.addHeader("Host", "alm.automic.com");
httpGet.addHeader("User-Agent",
"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0");
httpGet.addHeader("Accept",
"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
httpGet.addHeader("Accept-Language", "en-US,en;q=0.5");
httpGet.addHeader("Accept-Encoding", "gzip, deflate");
if (cookies.size() > 1)
httpGet.addHeader("Cookie",
cookies.get(cookies.size() - 1).split(";")[0]);
httpGet.addHeader("Connection", "keep-alive");
// Execute and get the response.
HttpResponse response = httpclient.execute(httpGet);
Header[] responseHeaders = response.getAllHeaders();
String location = "https://alm.automic.com/jama/login.req;";
for (int i = 0; i < responseHeaders.length; i++)
{
if (responseHeaders[i].getName().equals("Set-Cookie"))
{
if (responseHeaders[i].getValue().split(";")[0].split("=")[0]
.equals("JSESSIONID"))
cookies.add(responseHeaders[i].getValue());
}
if (responseHeaders[i].getName().equals("Location"))
{
location = responseHeaders[i].getValue();
}
}https://stackoverflow.com/questions/31342556
复制相似问题