I have an assigment were I'm supposed to validate a captcha. But I can't get the captcha image to get loaded into my GUI. I have two classes so far. First the ParsCaptcha.java class that contains the method getImage()
And the GUI:
But I can't get the image to show up in the frame that my GUI creates. At the end of the GUIconstructor I have put a system.out.println("TestKonstruktor"); just to check that the program goes through the methods. And I do get TestKonstruktor in the console. And there is n NullPointerException. The method getTextBetween returns "" if startindex is null. But with System.out.println("start:" + start); the console prints out
start:<image>
start:<url>
So, it seems to be OK there as well. Does anyone understand were to find the solution? Or, is there something with the GUI? ( I am not using the actionPerformed method right now )
Anders
Anders Kviback
Greenhorn
Joined: Mar 21, 2011
Posts: 26
posted
0
Just after submitting I saw that in the method getTextBetween startindex and endindex do get values -1 so getTextBetween will return "". But why then do they get the values -1?
Because of how indexOf behaves. If it can find the string, it will return the index. If it can't find the string it returns garbage data (-1), which means that the substring you're looking for doesn't exist.
What is the content of sb (line 99) and does it contain the text "<image>"?
Everything is theoretically impossible, until it is done. ~Robert A. Heinlein
Anders Kviback
Greenhorn
Joined: Mar 21, 2011
Posts: 26
posted
0
Thank you for answering,
If I do a System.out.println(sb.toString()); after line 100 ie
Nothing happens ie it doesn't seem to be a string there. ?? So , for some reason, my piece of code isn't reading what I want it to. I can't figure out what?
Anders
Anders Kviback
Greenhorn
Joined: Mar 21, 2011
Posts: 26
posted
0
I saw a mistake here. I had the wrong class in main in the GUI class. Now I've fixed that. So, here is what I get when putting in system.out.println(sb.toString()) at createParser():
ÿØÿà a lot of squares CREATOR: gd-jpeg v1.0 (using IJG JPEG v80), default qualityÿÛ a lot of asquares plus much more
So, there is something being read. But I'm obviously not getting the imageicon. So, am I not using the correct code to read the stream, in createPareser() ie:
or should I change the tags, to read inbetween, ie should it be something else instead of <image> and <url> in the getImage() method.
Or, is it something wrong in my handling in GUI?
Someone?
Michael Dunn
Rancher
Joined: Jun 09, 2003
Posts: 4041
posted
0
> Or, is it something wrong in my handling in GUI?
Tina Smith wrote:It's something fundamentally wrong with your assumption of what you are reading. It's not HTML (check the content-type of the HTTP header below).
I used Fiddler to check the content that is sent over the HTTP connection: it returned the following:
HTTP/1.1 200 OK
Date: Sun, 12 Feb 2012 22:44:56 GMT
Server: Apache/2.2.20 (FreeBSD) PHP/5.3.5 with Suhosin-Patch mod_ssl/2.2.20 OpenSSL/0.9.8q
X-Powered-By: PHP/5.3.5
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Last-Modified: Sun, 12 Feb 2012 22:44:56 GMT
Content-Length: 6266
Connection: close
Content-Type: image/jpeg
...
Hmm...
luck, db
There are no new questions, but there may be new answers.
Anders Kviback
Greenhorn
Joined: Mar 21, 2011
Posts: 26
posted
0
Yes, the picture is there. So, the GUI is working, but this is not HTML code. I compared this to another piece of code I have were I read RSS. And in that code I saw the HTML tags. But here there are no html tags. I'm stuck. I have to read the captcha code but I do not understand how?
Anyone?
Did you really think you would read the captcha code from whatever the server serves up? That would defeat the very purpose of a captcha, which is to verify that a human is responding.
What exactly are you trying to achieve?
Anders Kviback
Greenhorn
Joined: Mar 21, 2011
Posts: 26
posted
0
hello, again!
I misunderstood the assignment. The captcha was created at a server and we had to use a special webaddress to get the captcha and then to validate the captcha with another address. Thanks a lot though that you've taken you're time here. Though, I solved the assignment.
Anders
subject: Can't get ImageIcon to show up from captcha