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
Post a Comment