Results 1 to 5 of 5
Thread: URLConnection
- 02-18-2013, 04:59 PM #1
Member
- Join Date
- Feb 2013
- Posts
- 3
- Rep Power
- 0
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:
Java 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(); } }
- 02-18-2013, 05:06 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
Re: URLConnection
And?
Please do not ask for code as refusal often offends.
- 02-18-2013, 05:11 PM #3
Member
- Join Date
- Feb 2013
- Posts
- 3
- Rep Power
- 0
Re: URLConnection
and it doesnt work and it outputs the websites HTML code
- 02-18-2013, 05:20 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
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?Please do not ask for code as refusal often offends.
- 02-18-2013, 05:22 PM #5
Member
- Join Date
- Feb 2013
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
URLConnection
By tnrh1 in forum New To JavaReplies: 9Last Post: 12-20-2011, 02:03 PM -
UrlConnection question(s)
By dhazwa in forum New To JavaReplies: 1Last Post: 08-31-2011, 09:56 AM -
Lock between URLConnection and System.in
By mab in forum NetworkingReplies: 1Last Post: 02-24-2011, 12:21 PM -
URLConnection Efficiency
By Lil_Aziz1 in forum New To JavaReplies: 22Last Post: 08-19-2010, 06:27 PM -
Opening URLConnection
By Java Tip in forum Java TipReplies: 0Last Post: 11-24-2007, 07:37 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks