-
URLConnection
Hey I'm relatively new to networking in Java but i have created some client/server programs. However, in this program im trying to post to a URL. i want the user to enter a word, and that word to be searched up in dictionary.reference.com and the results to be sent back. here is my code:
Code:
package networking;
import java.net.*;
import java.io.*;
import java.util.Scanner;
public class Website {
static Scanner iScan = new Scanner(System.in);
public static void main(String args[]) throws Exception
{
URL dict = new URL("http://www.dictionary.reference.com/");
URLConnection yc = dict.openConnection();
yc.setDoOutput(true);
System.out.println("Word: ");
String word = iScan.nextLine();
word = URLEncoder.encode(word, "UTF-8");
OutputStreamWriter out = new OutputStreamWriter(yc.getOutputStream());
out.write("q=" + word);
out.close();
BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
}
-
Re: URLConnection
-
Re: URLConnection
and it doesnt work and it outputs the websites HTML code
-
Re: URLConnection
Then I'd look at what the website is expecting.
Sounds like it's not expecting a simple post of a word.
Is there some documentation?
-
Re: URLConnection
i looked at the source code to find out the id of the search which was "q"
and theres no documentation but i contacted the websites owners