posting data using urlconnection

How can I post data to a url using the urlconnection class.the data to be posted is a string.
I also need to set the content type, can you show what I need to set as the content type

thanks in advance
inzaghiAsked:
Who is Participating?
 
inzaghiAuthor Commented:
dont I need to set the content type?
0
 
girionisCommented:
As for the content type I already answered to you here: http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_21901926.html (my very first comment)
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
girionisCommented:
inzaghi,
> dont I need to set the content type?

YOu will need to use the following: urlConn.setRequestProperty("Content-Type", "<your content type here>");
0
 
inzaghiAuthor Commented:
what content type is set for strings
0
 
girionisCommented:
YOU do not need to set any content type for strings.
0
 
girionisCommented:
Maybe you can try plain/text. Are you sending form parameters?
0
 
girionisCommented:
> plain/text

text/plain I mean
0
 
inzaghiAuthor Commented:
Is it correct, u only set the content type for post operations and not for get?
0
 
girionisCommented:
Hmm... Not sure but I guess yes, since with GET you cannot send binary data or XML for instance, just strings.
0
 
Mayank SConnect With a Mentor Associate Director - Product EngineeringCommented:
You don't need to set it for GET (I don't remember doing it but still got the output).
0
 
girionisCommented:
:)
0
All Courses

From novice to tech pro — start learning today.