Sending a POST Request Using a Socket
See also Sending a POST Request Using a URL.
try {
// Construct data
String data = URLEncoder.encode("key1", "UTF-8") + "=" + URLEncoder.encode("value1", "UTF-8");
data += "&" + URLEncoder.encode("key2", "UTF-8") + "=" + URLEncoder.encode("value2", "UTF-8");
// Create a socket to the host
String hostname = "hostname.com";
int port = 80;
InetAddress addr = InetAddress.getByName(hostname);
Socket socket = new Socket(addr, port);
// Send header
String path = "/servlet/SomeServlet";
BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), "UTF8"));
wr.write("POST "+path+" HTTP/1.0\r\n");
wr.write("Content-Length: "+data.length()+"\r\n");
wr.write("Content-Type: application/x-www-form-urlencoded\r\n");
wr.write("\r\n");
// Send data
wr.write(data);
wr.flush();
// Get response
BufferedReader rd = new BufferedReader(new InputStreamReader(socket.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
// Process line...
}
wr.close();
rd.close();
} catch (Exception e) {
}
something is wrong in your code:
it's not : Socket socket = new Socket(addr, port);
it's : Socket socket = new Socket(hostname , port);
Actually, the Socket API takes both forms.
Thanks It Works :)
hey if u wanna send the data to a PARTICULAR FIELD in the URL, that is, the webpage, then how do u do that?
Throws 400 Bad Request Error!
Very very useful website. it helped a lot...thank you very much.
Thanks,
was very useful
but more important IT'S WORKS :P
test
Hi,Anybody please help me, I have one value in one variable, I need to send it to another system using core java program via internet. I tried with socket program,but it works only with local system and LAN connection. please anybody tell how to send and accept data via internet.
fengying028 Casey GHD Lisseur hasLisseur GHD Midnight Deluxe Gift been GHD Lisseur Diamond 2010 charged Ghd Lisseur Rose with Edition limitée GHD Radiance Set seven Lisseur GHD Kiss counts, GHD Lisseur RARE Nouveau including Lisseur GHD MK4 Purple first Rose Lisseur GHD 2010 degree Ghd Lisseur Pure murder, Ghd Lisseur Salon aggravated child GHD lisseur abuse GHD édition Limitée and Ghd Lisseur Dark misleading Set cadeau GHD Midnight the police Lisseur GHD RARE in the GHD Hair Styling Set Lisseur death GHD Lisseur Red Lust of Lisseur GHD Purple Indulgence Caylee. If she Ghd Glattejern Danmark is Ghd Midnight Deluxe Danmark convicted of Ghd Midnight Gift Set first degree, Ghd Precious she could Ghd Pink Salg be sentenced Ghd pink Glattejern to death ghd-pink-2010-limited-editon-glattejern-p-8.html">Billige Ghd Pink by the Ghd Black Salg seven-woman, five-man Salg Ghd Diamond is expectedGhd Salon Salg to take Ghd Blue Salg another ghd-purple-indulgence-glattejern-p-16.html">Ghd Purple Salg 1-2 weeks before a verdict is reached.
Silt-Cheng “under a layer of red-colored mud as well as a layer of sand”Mens Belstaff XL 500 Jacket plump land. males and females construct homes but moreover in the direction of wild seashore subsequent CD,Belstaff Jackets Uk Online uncover a flat red-colored mud,Mens Belstaff Daytona Blouson Jacket irrigation Weir road,Mens Belstaff Jackets Shaun Shum, and so do about a comparable time, Liu Zhou Belstaff leather, after which employed a straight West shovel compact disk block.Mens Moncler Down Jackets Mens Belstaff Bags Approximate forming these things, Belstaff Jacket people’s names subsequent saying “turn up soil la sedan”.Belstaff UK s homes the real estate subsequent using constructing materials,Mens Belstaff Trialmaster Classic Tourist Jacket is this three hint eight human brain Womens Belstaff Jackets “turn up soil la sedan”.
Shortly UGG Australia Boots ended up viewed all above the U. Even people who don't personal a pair identify the models and make
Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog
Pretty good post. very worth to read , i will come back next time.
Very interseting , i make the remark of this blog , i will come back again . your blog is very interesting
Very interseting , i make the remark of this blog , i will come back again . your blog is very interesting
Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog
It is really useful , thank you for your code.
I like skecher shape ups sandals with fashion style.
One admits that today's life is high priced, nevertheless people need cash for various things and not every person gets enough cash. So to receive some business loans or credit loan should be good way out.
how do you implement the code... I have been trying but am still getting some difficulties :(
Your website suffers from spam
What the shite does buying shoes have to do with assassinations and conspiracy? Damn spammers!
Welcome to Cheap New Era Caps Shop!We offer wholesale cheap new era caps,New Era 59fifty Caps,New Era Snapback Caps,Wholesale New Era Caps,Wholesale New Era Fitted Caps. Fast shipping, free tax,lowest price,authentic quality!
When I saw your blog content, I have some reflections. But the time is short. So I only leave some words in your blog and still thank you for sharing.
We are your source for free Facebook Covers. Here you will find FB Covers or Facebook Timeline Covers (whatever you call it!). We will continue to add new fb covers on a daily basis.
Facebook Covers
Your blog is very informative and useful. You have written it very well. I have bookmarked your blog. Your blog written in very good, I like it very much, I will often come to.Thank you to let me see your blog, I love you blog style, very cool.Your blog too good, I will soon come back again, to keep at it.Your website is very beautiful, you do something great!!Your essay is good, I like it very much. Excellent Blog! I really admire your thinking and the way you have put these information in this post.
/\
||
wtf???
Tiffany Outlet Celebration Series tiffany factory outlet rings to commemorate a happy moment in life in Tiffany Outlet Store and Mother's Day is just the best time for a Tiffany Outlet Celebration Series Tiffany Outlet USA ring to extend my gratitude to the mothers. Round Brilliant cut tiffany love bracelet rectangular ladder line cutting Shop inlaid mosaic of diamonds, or pink or blue sapphire in the base of the platinum shine tiffany diamond anchor necklace warm and sweet. Diamonds or precious stones are hand-mounted on a narrow section or top tiffany snowflake necklace of the wide ring, showing the beauty of pebbles or flowers. Each ring to witness a precious moment in life.tiffany and company outlet Cascading wear, highlighting fashion charm Tiffany Rings Outlet
classic tiffany necklace Beautiful lines and shapes that is eternal tiffanyoutlet.us is the concept of jewelry designer. tiffany and co earrings concept into the design of the tiffany gold bracelet Elsa Peretti jewelry series. return to tiffany necklace series showing a neat emotional lines and elegant and simple style Tiffany Outlet jewelry on the natural, fresh appearance.Tiffany Co Outlet Stores Open Heart pendant hanging ornaments above the sterling silver necklace or wire rope Tiffany & Co Rings elegant Smart, it makes your head drunk on flow; Diamonds by the Yard, Tiffany & Co Necklace series of jewelry more modern, easier to wear tiffany co stud earrings line is smooth, pleasant touch Bean series jewelry, people naturally think of the meaning of the seeds of the origin of life
Outlet Karen Millen inject more designers Karen Millen Outlet Store elements to mainstream fashion women, beautiful, confident women highlight the refined, pleasant and delicate. The fashionable element to add more meaning to the brand value and vision. So far Karen Millen Cocktail Dress,Lace Dress exquisite clothing and gorgeous evening is always the brand representatives. Karen Millen Outlet proud of its unique style and excellent workmanship in Karen Millen Ireland
2012 Karen Millen Outlet obtaining satisfy by using their paces.Karen Millen Strapless Dresses high quality and low price,Karen Millen Outlet Reviews Good Reviews,NOW, is the probability to build up one of the probably the most within the Karen Burns earnings and chose within the broad wide range of 120 merchandise from Karen Millen Factory Outlet
2012 NBA playoff is coming,Buy Cheap NBA Jerseys,Go to watch the NBA Games,Wear Cheap Throwback NBA Jerseys Fuel for your team,purchasing Cheap NBA Jerseys Free Shipping From www.cheapnbajerseys-usa.com