本文整理汇总了Java中org.jsoup.Connection.Response方法的典型用法代码示例。如果您正苦于以下问题:Java Connection.Response方法的具体用法?Java Connection.Response怎么用?Java Connection.Response使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jsoup.Connection
的用法示例。
在下文中一共展示了Connection.Response方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getUserInfo
import org.jsoup.Connection; //导入方法依赖的package包/类
private UserInfo getUserInfo() {
UserInfo userInfo = new UserInfo();
try {
Connection.Response customerInfo = Jsoup.connect(VOICEMAIL_SERVICE_URI).cookies(loadCookies()).execute();
Document doc = customerInfo.parse();
Elements pseudo = doc.select("input[name=pseudo]");
Elements phoneNumber = doc.select("input[name=voip_num]");
Elements login = doc.select("input[name=login]");
Elements email = doc.select("input[name=email]");
Elements uid = doc.select("input[name=uid]");
userInfo.setPseudo((pseudo.size() > 0) ? pseudo.get(0).attr("value") : "");
userInfo.setPhoneNumber((phoneNumber.size() > 0) ? phoneNumber.get(0).attr("value") : "");
userInfo.setLogin((login.size() > 0) ? login.get(0).attr("value") : "");
userInfo.setEmail((email.size() > 0) ? email.get(0).attr("value") : "");
userInfo.setUid((uid.size() > 0) ? uid.get(0).attr("value") : "");
} catch (IOException e) {
e.printStackTrace();
}
return userInfo;
}
示例2: readData
import org.jsoup.Connection; //导入方法依赖的package包/类
public static void readData(String objId) {
Document doc;
String url = "http://skydot.lanl.gov/nsvs/star.php?num=" + objId + "&mask=6420";
try {
Jsoup.connect(url).get();
Connection.Response res = Jsoup.connect(url).execute();
doc = Jsoup.connect("http://skydot.lanl.gov/nsvs/print_light_curve.php").cookies(res.cookies()).get();
} catch (IOException e) {
e.printStackTrace();
return;
}
Elements trs = doc.getElementsByTag("tr");
trs.remove(0);
for (Element tr : trs) {
Double julianDate = Double.parseDouble(tr.child(0).text()) + 2450000.5;
PhotometricData data = new PhotometricData(julianDate.toString(), tr.child(1).text(), tr.child(2).text(), objId);
System.out.println(data.toCsv());
}
}
示例3: rip
import org.jsoup.Connection; //导入方法依赖的package包/类
@Override
public void rip() throws IOException {
String gid = getGID(this.url);
String theurl = "http://newsfilter.org/gallery/" + gid;
logger.info("Loading " + theurl);
Connection.Response resp = Jsoup.connect(theurl)
.timeout(5000)
.referrer("")
.userAgent(USER_AGENT)
.method(Connection.Method.GET)
.execute();
Document doc = resp.parse();
Elements thumbnails = doc.select("#galleryImages .inner-block img");
for (Element thumb : thumbnails) {
String thumbUrl = thumb.attr("src");
String picUrl = thumbUrl.replace("thumbs/", "");
addURLToDownload(new URL(picUrl));
}
waitForThreads();
}
示例4: login
import org.jsoup.Connection; //导入方法依赖的package包/类
private synchronized boolean login() throws IOException {
log.info("Authenticating to GS admin panel");
String username = getUsername();
String password = getPassword();
rateLimiter.acquire(2);
Connection.Response loginForm = Jsoup.connect(LOGIN_URL)
.method(Connection.Method.GET)
.userAgent(USER_AGENT)
.execute();
if (loginForm.statusCode() == 403) {
log.warn("Disabling panel due to 403");
enabled = false;
}
rateLimiter.acquire(2);
Document document = Jsoup.connect(LOGIN_URL)
.userAgent(USER_AGENT)
.data("logout", "1")
.data("username", username)
.data("password", password)
.data("query_string", "")
.cookies(loginForm.cookies())
.post();
session.clear();
session.putAll(loginForm.cookies());
return !isLoginPage(document);
}
示例5: postPageByUrl
import org.jsoup.Connection; //导入方法依赖的package包/类
public Document postPageByUrl(String url, String[][] params) throws IOException {
Connection connection = Jsoup.connect(url);
for (String[] data : params) {
connection.data(data[0], data[1]);
}
Connection.Response response = connection.cookies(getCookies())
.followRedirects(true)
.method(Connection.Method.POST)
.execute();
this.cookies.addItems(response.cookies());
return response.parse();
}
示例6: onPostExecute
import org.jsoup.Connection; //导入方法依赖的package包/类
@Override
protected void onPostExecute(Connection.Response response) {
super.onPostExecute(response);
if (response != null) {
String body = response.body();
if (body != null) {
// TODO 获取成功,保存到本地
LogUtils.d(body);
Type listType = new TypeToken<List<Course.CourseInfo>>() {
}.getType();
courseInfoList = gson.fromJson(body, listType);
// TODO 根据CourseId查询课程信息
if (!courseInfoList.isEmpty()) {
for (int i = 0; i < courseInfoList.size(); i++) {
new CoursePraiseInfoAsyncTask(context, onLoadCallback).execute(courseInfoList.get(i));
}
} else {
onLoadCallback.onFailed(Constant.Connect.ERROR);
}
} else {
onLoadCallback.onFailed(Constant.Connect.ERROR);
}
} else {
onLoadCallback.onFailed(Constant.Network.Network_ERROR);
}
}
示例7: doInBackground
import org.jsoup.Connection; //导入方法依赖的package包/类
@Override
protected Void doInBackground(Void... params) {
try {
Connection.Response loginform = Jsoup.connect("https://markattendance.webapps.snu.edu.in/public/application/login/login")
.method(Connection.Method.GET)
.validateTLSCertificates(false)
.execute();
page = Jsoup.connect("https://markattendance.webapps.snu.edu.in/public/application/login/loginAuthSubmit")
.data("cookieexists", "false")
.data("login_user_name", Netid)
.data("login_password", pass)
.validateTLSCertificates(false)
.cookies(loginform.cookies())
.post();
page = Jsoup.connect("https://markattendance.webapps.snu.edu.in/public/application/index/summary")
.cookies(loginform.cookies())
.get();
Log.d("Main", page.title());
if (!(page.title().startsWith("Login"))) connected = true;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
示例8: connectUser
import org.jsoup.Connection; //导入方法依赖的package包/类
/**
* Using login and password, connects a user to SABi.
*
* @return Map of cookies. Used to all actions after login.
*/
private Map<String, String> connectUser(String session, LibraryUserVo user) throws ConnectionErrorExecption {
try {
if(DebugUtils.DEBUG) Log.d(TAG, "Will connect: (" + user.userLogin + ", " + user.userPassword + ")");
Connection.Response login = Jsoup.connect("http://sabi.ufrgs.br/F/" + session + "?func=file&file_name=login-session")
.data("ssl_flag","Y","func","login-session","login_source","bor-info","bor_library","URS50","bor_id",user.userLogin,"bor_verification",user.userPassword,"x","0","y","0")
.method(Connection.Method.POST)
.timeout(60000)
.execute();
return login.cookies();
} catch (IOException | NullPointerException e) {
if(DebugUtils.ERROR) Log.e(TAG, "connectUser error: " + e.getMessage());
throw new ConnectionErrorExecption();
}
}
示例9: getCourse
import org.jsoup.Connection; //导入方法依赖的package包/类
@Override
public Map<String, String> getCourse(Map<String, String> session) {
Connection con3 = Jsoup.connect("http://ice.xjtlu.edu.cn/my").timeout(300000);
Connection.Response visit = null;
Document d2 = null;
Elements courseTitles = null;
try {
visit = con3.ignoreContentType(true).method(Connection.Method.GET).cookies(session).execute();
} catch (IOException ex) {
ex.printStackTrace();
}
if (visit != null) {
d2 = Jsoup.parse(visit.body());
}
if (d2 != null) {
courseTitles = d2.getElementsByClass("coursebox").select("h3"); // For 16-17 Edition
}
Map<String, String> courseMap = new TreeMap();
for (Element ele : courseTitles) {
courseMap.put(ele.select("a").attr("title"), ele.select("a").attr("href")); // For 16-17 Edition
}
return courseMap;
}
示例10: onPostExecute
import org.jsoup.Connection; //导入方法依赖的package包/类
@Override
protected void onPostExecute(Connection.Response response) {
if (response != null && response.statusCode() == 200) {
try {
Log.v(TAG, "Response to JSON request: " + response.body());
JSONObject root = new JSONObject(response.body());
if ("success".equals(root.getString("type"))) {
Activity activity = getFragment().getActivity();
activity.setResult(CommonActivity.RESPONSE_SYNC_SUCCESSFUL);
activity.finish();
return;
} else {
String message = root.getString("msg");
if (message != null) {
Toast.makeText(getFragment().getContext(), message, Toast.LENGTH_SHORT).show();
return;
}
}
} catch (JSONException e) {
Log.e(TAG, "Failed to parse JSON object", e);
}
}
Toast.makeText(getFragment().getContext(), "Could not sync.", Toast.LENGTH_SHORT).show();
}
示例11: maxBodySize
import org.jsoup.Connection; //导入方法依赖的package包/类
@Test
public void maxBodySize() throws IOException {
String url = "http://direct.infohound.net/tools/large.html"; // 280 K
Connection.Response defaultRes = Jsoup.connect(url).execute();
Connection.Response smallRes = Jsoup.connect(url).maxBodySize(50 * 1024).execute(); // crops
Connection.Response mediumRes = Jsoup.connect(url).maxBodySize(200 * 1024).execute(); // crops
Connection.Response largeRes = Jsoup.connect(url).maxBodySize(300 * 1024).execute(); // does not crop
Connection.Response unlimitedRes = Jsoup.connect(url).maxBodySize(0).execute();
int actualString = 280735;
assertEquals(actualString, defaultRes.body().length());
assertEquals(50 * 1024, smallRes.body().length());
assertEquals(200 * 1024, mediumRes.body().length());
assertEquals(actualString, largeRes.body().length());
assertEquals(actualString, unlimitedRes.body().length());
int actualDocText = 269541;
assertEquals(actualDocText, defaultRes.parse().text().length());
assertEquals(49165, smallRes.parse().text().length());
assertEquals(196577, mediumRes.parse().text().length());
assertEquals(actualDocText, largeRes.parse().text().length());
assertEquals(actualDocText, unlimitedRes.parse().text().length());
}
示例12: run
import org.jsoup.Connection; //导入方法依赖的package包/类
@Override
public void run() {
String xsrf = getXsrf();
Map<String, String> headers = new HashMap<>();
headers.put("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
headers.put("Content-Type", "application/x-www-form-urlencoded");
Map<String, String> datas = new HashMap<>();
datas.put("title", mTitle);
datas.put("content", mContent);
datas.put(ConstantUtil.KEY_XSRF, xsrf);
Map<String, String> cookies = getCookies();
if (!cookies.containsKey(ConstantUtil.KEY_XSRF)) {
cookies.put(ConstantUtil.KEY_XSRF, xsrf);
}
try {
Connection.Response res = Jsoup.connect(mUrl).cookies(cookies).headers(headers).data(datas).method(Connection.Method.POST).execute();
if (res.statusCode() == ConstantUtil.HTTP_STATUS_200 || res.statusCode() == ConstantUtil.HTTP_STATUS_302) {
successOnUI("发布成功");
return;
}
} catch (IOException e) {
e.printStackTrace();
}
failedOnUI("发布失败");
}
示例13: run
import org.jsoup.Connection; //导入方法依赖的package包/类
@Override
public void run() {
String xsrf = getXsrf();
Map<String, String> headers = new HashMap<>();
headers.put("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
headers.put("Content-Type", "application/x-www-form-urlencoded");
Map<String, String> datas = new HashMap<>();
datas.put(ConstantUtil.KEY_XSRF, xsrf);
Map<String, String> cookies = getCookies();
if (!cookies.containsKey(ConstantUtil.KEY_XSRF)) {
cookies.put(ConstantUtil.KEY_XSRF, xsrf);
}
try {
Connection.Response res = Jsoup.connect(mUrl).cookies(cookies).headers(headers).data(datas).method
(Connection.Method.GET).execute();
if (res.statusCode() == ConstantUtil.HTTP_STATUS_200 || res.statusCode() == ConstantUtil.HTTP_STATUS_302) {
successOnUI("成功");
return;
}
} catch (IOException e) {
e.printStackTrace();
}
failedOnUI("失败");
}
示例14: connect
import org.jsoup.Connection; //导入方法依赖的package包/类
static Map<String,String> connect() throws IOException{
Connection.Response res = Jsoup.connect("https://www.facebook.com/login.php")
.data("username", "[email protected]", "password", "password")
.timeout(30 * 1000)
.userAgent("Mozilla/5.0")
.method(Method.POST)
.execute();
Document doc = res.parse();
System.out.println(doc);
Map<String, String> loginCookies = res.cookies();
String sessionId = res.cookie("SESSIONID");
return loginCookies;
}
示例15: connect
import org.jsoup.Connection; //导入方法依赖的package包/类
static Map<String, String> connect() throws IOException {
// Connection.Response loginForm =
// Jsoup.connect("https://passport.weibo.cn/signin/login")
// .method(Connection.Method.GET)
// .execute();
//
// Connection.Response res =
// Jsoup.connect("https://passport.weibo.cn/signin/login")
// .data("username", "18241141433", "password", "152300")
// .data("ec", "0", "entry", "mweibo")
// .data("mainpageflag", "1", "savestate", "1")
// .timeout(30 * 1000)
// .userAgent("Mozilla/5.0")
// .cookies(loginForm.cookies())
// .method(Method.POST)
// .execute();
// Document doc = res.parse();
// System.out.println(doc);
Connection.Response loginForm = Jsoup.connect("https://www.oschina.net/home/login")
.method(Connection.Method.GET).execute();
Connection.Response res = Jsoup.connect("https://www.oschina.net/home/login").header("Host", "www.oschina.net")
.userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0")
.referrer("https://www.oschina.net/home/login")
.data("username", "[email protected]", "password", "lvmeng152300").data("save_login", "1")
.timeout(30 * 1000).cookies(loginForm.cookies()).method(Method.POST).execute();
Document doc = res.parse();
System.out.println(doc);
Map<String, String> loginCookies = res.cookies();
String sessionId = res.cookie("SESSIONID");
return loginCookies;
}