Android Post表单包括httpPost验证码
我想使用包含以下表单的页面:Android Post表单包括httpPost验证码,android,forms,http-post,captcha,Android,Forms,Http Post,Captcha,我想使用包含以下表单的页面: <form method="post" action="modules.php?name=search"> <input onkeypress=FKeyPress(this); onkeydown=FKeyDown(this); type="text" style="text-align:center" name="name" size="30"> </p> <img src='captch
<form method="post" action="modules.php?name=search">
<input onkeypress=FKeyPress(this); onkeydown=FKeyDown(this); type="text" style="text-align:center" name="name" size="30"> </p>
<img src='captcha.php' id='captcha' /><br /><br /><a href='#' onclick='document.getElementById("captcha").src="captcha.php?"+Math.random();document.getElementById("captchaf").focus ();'id='change-image'>change</a><br/><p><strong>Enter captcha</strong><br>
<input name="captcha" id="captchaf" type="text" style="text-align:center"></p><br />
<input name="fbrsecured" type="hidden" value="">
<input name="action" type="hidden" value="FBSend">
<p><input type="submit" name="submit" value="search"></p>
</form>
输入验证码
我要展示一下:
EditText edcap = (EditText) findViewById(R.id.cap);
ImageView cap = (ImageView) findViewById(R.id.capt);
try{
String url1 = "mysiteaddress/captcha.php";
URL ulrn = new URL(url1);
HttpURLConnection con = (HttpURLConnection)ulrn.openConnection();
InputStream is = con.getInputStream();
Bitmap bmp = BitmapFactory.decodeStream(is);
if (null != bmp)
cap.setImageBitmap(bmp);
else
System.out.println("The Bitmap is NULL");
}catch(Exception e){}
String capt = edcap.getText().toString();
HttpPost httpPost = new HttpPost("http://eservice.postcode.post.ir/modules.php?name=Postalcode2");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("name", Name));
nameValuePairs.add(new BasicNameValuePair("captcha", Capt));
nameValuePairs.add(new BasicNameValuePair("fbrsecured", ""));
nameValuePairs.add(new BasicNameValuePair("action", "FBSend"));
nameValuePairs.add(new BasicNameValuePair("submit", "search"));
EditText-edcap=(EditText)findViewById(R.id.cap);
ImageView cap=(ImageView)findViewById(R.id.capt);
试一试{
字符串url1=“mysiteaddress/captcha.php”;
URL ulrn=新URL(url1);
HttpURLConnection con=(HttpURLConnection)ulrn.openConnection();
InputStream=con.getInputStream();
位图bmp=BitmapFactory.decodeStream(is);
如果(null!=bmp)
cap.setImageBitmap(bmp);
其他的
System.out.println(“位图为空”);
}捕获(例外e){}
字符串capt=edcap.getText().toString();
HttpPost HttpPost=新的HttpPost(“http://eservice.postcode.post.ir/modules.php?name=Postalcode2");
List nameValuePairs=新的ArrayList();
添加(新的BasicNameValuePair(“name”,name));
添加(新的BasicNameValuePair(“captcha”,Capt));
添加(新的BasicNameValuePair(“fbrsecured”);
添加(新的BasicNameValuePair(“操作”、“FBSend”);
添加(新的BasicNameValuePair(“提交”、“搜索”);
我显示captcha并输入edcap,但出现了不正确的captcha错误。最后我找到了答案,我使用了2个httpclient,这更改了cookie并导致不正确的captcha错误。您设置了图像并立即尝试读取答案。您如何有时间在两行连续的代码之间输入文本<代码>cap.setImageBitmap(bmp);字符串capt=edcap.getText().toString()代码>。我认为你应该将验证码显示和发送分为两个不同的功能。我在两个独立的功能中完成这项工作。isue应该是html格式。我只使用过google recaptcha,它需要验证码密钥和验证码答案。但在你的例子中,你只使用了答案,我认为答案是不够的。我认为它是由phpsessid实现的,我不知道如何处理这个问题。嘿,你能分享你使用2 HttpClient的代码部分吗,因为我有同样的错误。