我是android系统的新手,它试图通过从网站获取数据,询问注册号和验证码,并在提交后显示内容来开发小型应用程序。但是我被页面本身的提交页面困住了,因为提交表单后,来自网络的响应是
站点代码
<tbody>
<tr>
<td></td>
</tr>
<tr id="vehiclesearchstatus:j_id_jsp_664471437_14">
<td id="vehiclesearchstatus:j_id_jsp_664471437_15">
<label class="wiproStyleText">Vehicle No:</label>
</td>
<td id="vehiclesearchstatus:j_id_jsp_664471437_17">
<input id="vehiclesearchstatus:regn_no1_exact" type="text"
name="vehiclesearchstatus:regn_no1_exact" autocomplete="off" value=""
class="wiproStyleinput" maxlength="10"
onblur="checkLength('regn_no1_exact',3)" onkeypress="return AlphaNumericOnly(event, '');" size="12" style="width:90px">
</td>
</tr>
<tr>
<td></td>
</tr>
<tr id="vehiclesearchstatus:j_id_jsp_664471437_19">
<td id="vehiclesearchstatus:j_id_jsp_664471437_20">
<label id="vehiclesearchstatus:lbl_RANDOM_NUMBER" class="wiproStyleText">Verification Code:</label>
</td>
<td id="vehiclesearchstatus:j_id_jsp_664471437_22">
<img alt="capatcha" src="/nrservices/cap_img.jsp" style="width: auto; height:30px;">
<img
id="vehiclesearchstatus:imageProcessBankNewImage"
src="/nrservices/images/refresh.bmp" onclick="window.location.reload()"
style="width: auto; height: 25px;"></td>
<td id="vehiclesearchstatus:j_id_jsp_664471437_24">
<input
id="vehiclesearchstatus:txt_ALPHA_NUMERIC" type="text"
name="vehiclesearchstatus:txt_ALPHA_NUMERIC" autocomplete="off" value=""
maxlength="10" size="8" style="width:90px;">
</td>
</tr>
</tbody>
我的代码
我被尝试了什么
inner class FetchFromVahan : AsyncTask<String, Void, String>() {
override fun doInBackground(vararg params: String): String? {
val userAgent =
"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36"
var loginForm: Connection.Response? = null
try {
val img = document.select("img#vehiclesearchstatus:imageProcessBankNewImage").first()
?: throw RuntimeException("Unable to locate image in ")
loginForm = Jsoup.connect("https://vahan.nic.in/nrservices/faces/user/jsp/SearchStatus.jsp")
.userAgent(userAgent)
.ignoreContentType(true)
.method(Connection.Method.GET)
.execute()
} catch (e: IOException) {
e.printStackTrace()
}
loginForm = Jsoup.connect("https://vahan.nic.in/nrservices/faces/user/jsp/SearchStatus.jsp")
.cookies(loginForm!!.cookies())
.ignoreContentType(true)
.data("vehiclesearchstatus:regn_no1_exact", regN)
.data("vehiclesearchstatus:txt_ALPHA_NUMERIC", reC)
.userAgent(userAgent)
.method(Connection.Method.POST)
.followRedirects(true)
.execute()
var document: Document? = null
if (loginForm != null) {
try {
document = Jsoup.connect("https://vahan.nic.in/nrservices/faces/user/jsp/SearchStatus.jsp")
.cookies(loginForm.cookies())
.userAgent(userAgent)
.get()
System.out.println(document)
} catch (e: IOException) {
e.printStackTrace()
}
}
return document!!.toString()
}
override fun onPostExecute(result: String) {
super.onPostExecute(result)
}
}
加载验证码
val imgSrc = img.absUrl("https://vahan.nic.in/nrservices/cap_img.jsp")
val bitmaps = BitmapFactory.decodeStream(URL(imgSrc).content as InputStream)
image.setImageBitmap(bitmaps)
button.setOnClickListener {
FetchFromVahan().execute()
}