title: Reverse image search using Google api
body: <p>I am trying to write a java program which for loop the image files in a folder and<br>
  do reverse image search on google (just trying to do with one image in this question) </p>
  
  <p>I find some example like below and the result will give me a url that preformed the reverse image search.<br>
  While I am wondering how can I download one of the image from the result site.</p>
  
  <p>Some things to add is that I have read the new google api(?) and I find that it only allow me to do search 100/day, hence I choose to use the old version(?) although it warn me the method are deprecated.</p>
  
  <pre><code>import java.io.BufferedReader;
  import java.io.File;
  import java.io.IOException;
  import java.io.InputStreamReader;
  
  import org.apache.http.HttpResponse;
  import org.apache.http.client.ClientProtocolException;
  import org.apache.http.client.HttpClient;
  import org.apache.http.client.methods.HttpPost;
  import org.apache.http.entity.mime.MultipartEntity;
  import org.apache.http.entity.mime.content.FileBody;
  import org.apache.http.entity.mime.content.StringBody;
  import org.apache.http.impl.client.DefaultHttpClient;
  
  public class ReverseImageSearch{
    public static void main(String args[]){
      try {
        HttpClient client = new DefaultHttpClient();
        String url="https://www.google.co.in/searchbyimage/upload";
        String imageFile="C:\\Users\\Chan\\Desktop\\pixiv29706591.jpg";
        HttpPost post = new HttpPost(url);
  
        MultipartEntity entity = new MultipartEntity();
        entity.addPart("encoded_image", new FileBody(new File(imageFile)));
        entity.addPart("image_url",new StringBody(""));
        entity.addPart("image_content",new StringBody(""));
        entity.addPart("filename",new StringBody(""));
        entity.addPart("h1",new StringBody("en"));
        entity.addPart("bih",new StringBody("179"));
        entity.addPart("biw",new StringBody("1600"));
  
        post.setEntity(entity);
        HttpResponse response = client.execute(post);
        BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));         
  
        String line = "";
        while ((line = rd.readLine()) != null) {
          if (line.indexOf("HREF")&gt;0)
              System.out.println(line.substring(8));
             //Problem:
             // get one of the result image from the sites
             // and store it in my PC
  
  
        }
  
      }catch (ClientProtocolException cpx){
        cpx.printStackTrace();
      }catch (IOException ioex){
        ioex.printStackTrace();
      }
   }
  }
  </code></pre>