Monday 15 July 2013

java - HTTP Request passing Keywords to search -


I did some research to solve my problem but unfortunately I could not do so yet. This is not such a big deal, but I have caught it.

I have to search for some keywords in keywords like search engine like Google, I've got two classes to do this: < Pre> package com.sh.st; Import java.awt.event.ActionEvent; Import java.awt.event.ActionListener; Search-Screen Tools Executioner (Public Event Search) in Public Category Event Search {btsearch.addActionListener (this); } Public Zero Functionality (Action Event e) {if (e.getSource () == BTS Search) {String Query = Txtish.Get Text}; }}}

and

  package com.sh.st; Import java.io.InputStream; Import java.net.URL; Import java.net.URLConnection; Public class HttpRequest SearchScreen extends {url url = new URL ("google.com" + "?" + Query) OpenConnection (); URL Connection Connection = url.openConnection (); Connection.setRequestProperty ("Accept-Charset", "UTF-8"); // potential incompatibility InputStream response = connection.getInputStream (); }   

Then, txtsearch comes from another category called SearchScreen and I have attributed the value to a string named Query. I need to pass the query to the HttpRequest class and to do this I just expand, I'm sure this is wrong, but I have seen someone else do this; And this is the first problem, how can I do this?

The second and most important I am receiving a syntax error:

 Enter image details here  Enter image details here

I received the" connection.setRequestProperty "(" Accept-Charset "," UTF-8 "), and did not fully understand the utility; "Reading course, I can understand that about cactors that might come from my request, but even though syntax error is not clear to me

I did research in relation to this type of:

  • All of them have a good content but I can not fully understand this But everything and the part I am trying to follow is not working Do anyone help me

    Edit: [Subject Solution]

    Try it Code: (Comments inline)

      // Fixed Search URL; and URL url = New URL ("http://google.com/search?q=" + query ) Open connection (); // Setup connection properties (this connection does not open) URLConnection connection = url.openConnection (); Connection.setRequestProperty ("Accept-Charset", "UTF-8"); // Actually In, open the HTTP Connection Connection. Connect (); // Setup A Reader BufferedReader Reader = New BufferedReader (New Inputstrymrider (Knekshnkgetinputstram ())); Line line line = line read by line = zero; While ((line = reader.readline ()) = null {} System.out.println (line); } // close connection reader Close ();    

  • No comments:

    Post a Comment