Results 21 to 31 of 31
Thread: [SOLVED] http request
- 04-08-2008, 11:56 AM #21
- 04-08-2008, 12:03 PM #22
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
ah, actually I'm displaying that on a JEditorPane. So I can work with HTML code there.
- 04-08-2008, 12:29 PM #23
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
I got the point. I couldn't concatenate those strings, because of the tab space effecting. I solved my problem. It's working fine.
- 04-08-2008, 12:58 PM #24
Nice one Eranga. :D
Did this post help you? Please
me! :cool:
- 04-08-2008, 01:08 PM #25
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Yep, up to now it's working really well. :)
- 11-25-2008, 01:12 AM #26
Member
- Join Date
- Nov 2008
- Posts
- 2
- Rep Power
- 0
A slightly more complicated example
If you get your own test code from the Post Office and use the link to their DLL, this would work.
public void doPost() {
try {
// Construct data
String data = URLEncoder.encode("API", "UTF-8") + "=" + URLEncoder.encode("ZipCodeLookup","UTF-8");
data += "&";
data += URLEncoder.encode("XML", "UTF-8") + "=" + URLEncoder.encode("<ZipCodeLookupRequest USERID=\"??????????\"><Address ID=\"0\"><Address1></Address1><Address2>6406 Ivy Lane</Address2><City>Greenbelt</City><State>MD</State></Address></ZipCodeLookupRequest>", "UTF-8");
// Send data
URL url = new URL("<post office API DLL LINK>");
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();
// Get the response
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
System.out.println(line);
}
wr.close();
rd.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
- 11-26-2008, 07:45 AM #27
You may want to look at the Apache httpclient code library.
The pure Java stuff works for trivial servers, but tends to break down on real web pages from real servers. The Apache code handles "chunked" results, encoding, compression, and lots of other stuff.
Of course, if you control both ends, the response from the Web server really should be XML so you can parse it on the client side
- 11-26-2008, 01:25 PM #28
As fishtoprecords said look into HttpCleint,Here is the brief tutorial for HttpClient,it is very easy to use it:
HttpClient - HttpClient Tutorial
- 11-27-2008, 03:38 AM #29
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Thanks for the tutorial serjant. I've already found that when I post at the time around I start this thread. :) Did you find that any server side application related to this tutorial.
- 11-27-2008, 03:47 AM #30
- 11-27-2008, 04:35 AM #31
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Thanks fishtoprecords, actually I've solve the question here. So it's time to mark it as solved. :)
Similar Threads
-
respose with out request
By karthikiniyan in forum Java ServletReplies: 1Last Post: 04-09-2008, 03:06 PM -
How to use request Scope in Spring
By JavaBean in forum Java TipReplies: 0Last Post: 09-28-2007, 12:46 PM -
Generate XML request from web form
By sabatier in forum XMLReplies: 1Last Post: 08-09-2007, 07:53 PM -
Help with request.getParameter()
By Albert in forum Enterprise JavaBeans (EJB)Replies: 1Last Post: 07-13-2007, 03:39 PM -
HttpServletRequest request size
By Ed in forum Java ServletReplies: 2Last Post: 07-02-2007, 02:02 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks