Я пытался отобразить капчу для пользовательского ввода на свинг-панели, а затем опубликовать текст капчи вместе с другой информацией, чтобы получить доступ к публичной информации о компании (в Бразилии).Кстати, я не хочу делать робота и не сломать / взломать капчу, я просто не хочу избегать просмотра, а затем получать и регистрировать некоторую информацию из Интернета на моей базе данных.
До сих пор мне удалось отобразить капчу, но я не могу понять, почему мне не удается при публикации.
вот ссылка на страницу: http://www.receita.fazenda.gov.br/pessoaJuridica/CNPJ/CNPJREVA/CNPJREVA_solicitacao2.asp
Форма в основном следующая:
<form id="theForm" action="" onSubmit="javascript:return Submeter();" method="post" name="frmConsulta">
<input type="hidden" name="origem" value="comprovante">
<input tabIndex="1" name="cnpj" maxlength="14" size="16" onKeyup="SaltaCampo(document.frmConsulta.cnpj, document.frmConsulta.chave, 14, event)"value="">
<input type="text" tabIndex="2" id="idLetra" name="idLetra" maxlength="4" size="6">
<input type="text" id="idSom" name="idSom" size="7" maxlength="6" tabindex="4">
<input type="submit" value="Consultar" id=submit1 name=submit1>
<input type="hidden" name="search_type" value="cnpj">
<input type="reset" name="opcao" value="Limpar">
</form>
Функция javascript onSubmit:
function Submeter()
{
document.cookie = 'flag=1';
if (validaCaracteresCaptcha('theForm', 'idLetra', 'idSom', 'valida.asp') == false)
{
return false;
}
}
функция validaCaracteresCaptcha:
function validaCaracteresCaptcha(nomeForm, idLetra, idSom, paginaDestino)
{
var form = document.getElementById(nomeForm);
if (document.getElementById(idLetra).value == "" && document.getElementById(idSom).value == "")
{
AlertaCaptcha("Favor preencher algum dos campos de validação");
form.action= "";
return false;
}
if (document.getElementById(idLetra).value != "" && document.getElementById(idSom).value != "")
{
AlertaCaptcha("Favor preencher apenas um dos campos de validação");
form.action="";
return false;
}
form.action=paginaDestino;
return true;
}
и две функции, которые я использую, чтобы получить капчу и затем опубликовать информацию (java):
protected void getCaptcha()
{
try
{
URL url = new URL ("http://www.receita.fazenda.gov.br/pessoaJuridica/CNPJ/CNPJREVA/valida.asp");
// URL connection channel.
urlConn = (HttpURLConnection) url.openConnection();
URL cUrl = new URL("http://www.receita.fazenda.gov.br/scripts/srf/intercepta/captcha.aspx?opt=image");
lblCaptcha.setIcon(new ImageIcon(cUrl));
// Let the run-time system (RTS) know that we want input.
urlConn.setDoInput (true);
// Let the RTS know that we want to do output.
urlConn.setDoOutput (true);
// No caching, we want the real thing.
urlConn.setUseCaches (false);
// Specify the content type.
urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
urlConn.setRequestMethod("POST");
urlConn.setConnectTimeout(0);
urlConn.connect();
//
}
catch(Exception e)
{
e.printStackTrace();
}
}
private void postIt()
{
try
{
// Send POST output.
DataOutputStream printout = new DataOutputStream (urlConn.getOutputStream ());
String content = "origem=comprovante&cnpj="+txtCnpj.getText()+"&idSom="+txtCaptcha.getText()+"&search_type=cnpj";
printout.writeBytes (content);
printout.flush ();
printout.close ();
// Get response data.
if(urlConn.getResponseCode()==HttpURLConnection.HTTP_OK)
{
BufferedReader reader = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
String str = "";
while((str = reader.readLine()) != null)
{
System.out.println(str);
}
reader.close ();
}
else
System.out.println("Answer not received");
}
catch(Exception e)
{
e.printStackTrace();
}
}
и все.Заранее спасибо!