title: Java Apache Httpclient and ImageIO read captcha from URL
body: <p>I am writing a program to do the following job: </p>
  
  <ol>
  <li>read a captcha from URL which the captcha image will change every time. 
  e.g. domain/captcha.do 
  It will return an image with 3 letters displays </li>
  <li>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: domain/doesitpass.do?capvalue=QWE and proceed the get/post. </li>
  <li>In Chrome/Firefox, I open a tab and then go to domain/captcha.do first, it returns 3 letters (e.g. ZXC), then I open a new tab and then paste as domain/doesitpass.do?capvalue=ZXC, it will return a json {"error":"0","passcode":"blablablaXXX"} </li>
  <li>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 domain/doesitpass.do?capvalue=ZXC will returns {"error":"1"} which means incorrect passcode. </li>
  </ol>
  
  <p>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. </p>
  
  <p>Part of my codes is as follows: </p>
  
  <pre><code>Scanner sd=new Scanner(System.in); 
  
  imgStr = "domain/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 = "domain/doesitpass.do?capvalue=" + imageValue 
  
  // or httpPost, both try, same result 
  httpGet = new HttpGet(passcodeURL); 
  response = httpclient.execute(httpGet); 
  </code></pre>
  
  <p>Sorry for my poor English. Any help would be highly appreciated. </p>