Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/464.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在Swing面板中显示验证码_Java_Javascript_Html_Swing - Fatal编程技术网

Java 在Swing面板中显示验证码

Java 在Swing面板中显示验证码,java,javascript,html,swing,Java,Javascript,Html,Swing,我一直在尝试在swing面板中显示用户输入的验证码,然后将验证码文本与其他信息一起发布,以便访问有关公司(在巴西)的一些公共信息。顺便说一句,我不想做一个机器人,也不想破坏/破解验证码,我只是不想避免浏览,然后在我的数据库上从互联网上获取和注册一些信息 到目前为止,我已经设法显示验证码,但我不明白为什么我张贴时没有成功 以下是该页面的链接: 形式基本如下: <form id="theForm" action="" onSubmit="javascript:return Submeter()

我一直在尝试在swing面板中显示用户输入的验证码,然后将验证码文本与其他信息一起发布,以便访问有关公司(在巴西)的一些公共信息。顺便说一句,我不想做一个机器人,也不想破坏/破解验证码,我只是不想避免浏览,然后在我的数据库上从互联网上获取和注册一些信息

到目前为止,我已经设法显示验证码,但我不明白为什么我张贴时没有成功

以下是该页面的链接:

形式基本如下:

<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>
ValidAracterEscaptCha函数是:

function Submeter()
{

    document.cookie = 'flag=1';

    if (validaCaracteresCaptcha('theForm', 'idLetra', 'idSom', 'valida.asp') == false)
    {
        return false;
    }       
}
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):


就这样。提前谢谢

你能告诉我当你试图发布信息时会发生什么吗?然后页面将我的连接重定向到同一个页面,就好像我没有发布正确的验证码组合一样。顺便说一句,我相信这与将验证码图像提取到JLabel中有关。可能ImageIcon(url)构造函数正在调用另一个连接,这显然会杀死每个连接一个图像的captcha安全机制在内容字符串中使用“idLetra”而不是“idSom”。这是我的第一个猜测,我尝试了idLetra,然后是idSom,但仍然得到了相同的答案
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();
    }
}