If you want to send String only try this way:
String str = "some string goes here"; byte[] outputInBytes = str.getBytes("UTF-8"); OutputStream os = conn.getOutputStream(); os.write( outputInBytes ); os.close(); But if you want to send as Json change Content type to:
conn.setRequestProperty("Content-Type","application/json"); and now our str we can write:
String str = "{'x'\"x\": 'val1'\"val1\",'y'\"y\":'val2'\"val2\"}"; Hope it will help,