Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #30234 > unrolled thread

Apache Httpclient and ImageIO read captcha from URL

Started byXiao <foolsmart2005@gmail.com>
First post2014-10-29 08:22 -0700
Last post2014-10-29 08:22 -0700
Articles 1 — 1 participant

Back to article view | Back to comp.lang.java.programmer


Contents

  Apache Httpclient and ImageIO read captcha from URL Xiao <foolsmart2005@gmail.com> - 2014-10-29 08:22 -0700

#30234 — Apache Httpclient and ImageIO read captcha from URL

FromXiao <foolsmart2005@gmail.com>
Date2014-10-29 08:22 -0700
SubjectApache Httpclient and ImageIO read captcha from URL
Message-ID<9bdc64e9-b715-4aff-b696-ea8263d70b7a@googlegroups.com>
Hi All,

I am writing a program to do the following job:

1. read a captcha from URL which the captcha image will change every time. 
e.g. http://abc.com/captcha.do
It will return an image with 3 letters displays
2. my program will wait for input the 3 letters and then submit to do checking.
e.g. the captcha value is "QWE", user input "QWE" and my program will build the URL string: http://abc.com/doesitpass.do?capvalue=QWE and proceed the get/post.
3. In Chrome/Firefox, I open a tab and then go to http://abc.com/captcha.do first, it returns 3 letters (e.g. ZXC), then I open a new tab and then paste as http://abc.com/doesitpass.do?capvalue=ZXC, it will return a json {"error":"0","passcode":"blablablaXXX"}
4. However, in the eclipse development tool, I call the captcha.do first, save the image to a temporary folder, then type the 3 letters by observe the image letters (e.g. ZXC) to the input console, submit to http://abc.com/doesitpass.do?capvalue=ZXC will returns {"error":"1"} which means incorrect passcode.

My question is, why in browser view, Step 3 can get the correct message while in 4, it cannot? And how I can make my program to pass the checking? Thanks.

Part of my codes is as follows:


Scanner sd=new Scanner(System.in);

imgStr = "http://abc.com/captcha.do"

URL url=new URL(imgStr);
BufferedImage img1 = ImageIO.read(url);
ByteArrayOutputStream osByteArray = new ByteArrayOutputStream();
ImageIO.write(img1, "jpg", new File("C://image//test.jpg"));

imageValue = sd.nextLine();

passcodeURL = "http://abc.com/doesitpass.do?capvalue=" + imageValue

// or httpPost, both try, same result
httpGet = new HttpGet(passcodeURL);
response = httpclient.execute(httpGet);

Sorry for my poor English. Any help would be highly appreciated.

[toc] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web