java - Http Post With Body -


i have sent method in objective-c of sending http post , in body put string:

nsstring *requestbody = [nsstring stringwithformat:@"mystring"]; nsmutableurlrequest *request = [nsmutableurlrequest requestwithurl:url]; [request sethttpmethod:@"post"]; [request sethttpbody:[requestbody datausingencoding:nsutf8stringencoding]]; 

now in android want same thing , looking way set body of http post.

you use snippet -

httpurlconnection urlconn; url murl = new url(url); urlconn = (httpurlconnection) murl.openconnection(); ... //query body urlconn.addrequestproperty("content-type", "application/" + "post"); if (query != null) { urlconn.setrequestproperty("content-length", integer.tostring(query.length())); urlconn.getoutputstream().write(query.getbytes("utf8")); } 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -