我需要以编程方式浏览网站。仅WebView
只有图形输出
所以,我想在后台加载一个html,填写一个字段并执行点击提交按钮
P. S.为什么需要我。 - 因为我需要覆盖网站登录表单,但我无法通过HttpsURLConnection
模拟html表单发布方法。我认为在cookie中存在这个问题并且重新发布它但它没有帮助。
ADDED
如果有人可以帮助HttpsURLConnection
,那么我会尝试使用https://www.instagram.com/accounts/login/?force_classic_login=&next=/oauth/authorize/%3Fclient_id%CLIENT_ID%26redirect_uri%3Dhttps%3A//test.com/instagram/auth%26response_type%3Dcode
链接。
我可以在Chrome中打开此链接,但HttpsURLConnection
在日志中写入未找到该文件。我在网上是noobie所以我真的无法理解问题
我从Instagram登录页面的html中获取此链接。
这是我向Instagram服务发送登录名和密码的代码:
public static String requestCode(final String username, final String password) throws IOException {
Values args = new Values(3);
args.add(KEY_CLIENT_ID, CLIENT_ID);
args.add(KEY_RESPONSE_TYPE, "code");
args.add(KEY_REDIRECT_URI, REDIRECT_URI);
HttpsURLConnection connection = new HttpsRequest(URL_AUTH)
.setCacheMode(CacheMode.DISABLED)
.setRequestArguments(args)
.build();
Map<String, List<String>> map = connection.getHeaderFields();
List<String> cookies = map.get("Set-Cookie");
CookieManager cookieManager = new CookieManager();
for (String cookie : cookies) {
cookieManager.getCookieStore().add(null, HttpCookie.parse(cookie).get(0));
}
final String csrfToken = getCsrfToken(cookies);
connection.disconnect();
if (!TextUtils.isEmpty(csrfToken)) {
Values properties = new Values(1);
properties.add("Cookie",
TextUtils.join(";", cookieManager.getCookieStore().getCookies()));
Values bodyArgs = new Values(3);
bodyArgs.add("csrfmiddlewaretoken", csrfToken);
bodyArgs.add("username", username);
bodyArgs.add("password", password);
final String additionalUrl = "?" + KEY_CLIENT_ID + "=" + CLIENT_ID + "&"
+ KEY_REDIRECT_URI + "=" + REDIRECT_URI + "&"
+ KEY_RESPONSE_TYPE + "=code";
final String url = URL_LOGIN + "?force_classic_login=&next=/oauth/authorize/"
+ URLEncoder.encode(additionalUrl, "UTF-8");
connection = new HttpsRequest(url)
.setRequestMethod(HttpsRequest.POST)
.setRequestProperties(properties)
.setBodyArguments(bodyArgs)
.setCacheMode(CacheMode.DISABLED)
.build();
final String answer = ConnectionUtils.readToString(connection.getInputStream());
connection.disconnect();
Log.d(TAG, "Answer: " + answer);
}
return null;
}
我用过的