Skip to main content
added 8 characters in body
Source Link
Maxim Shoustin
  • 78k
  • 29
  • 212
  • 229

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,

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': 'val1','y':'val2'}"; 

Hope it will help,

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\": \"val1\",\"y\":\"val2\"}"; 

Hope it will help,

Source Link
Maxim Shoustin
  • 78k
  • 29
  • 212
  • 229

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': 'val1','y':'val2'}"; 

Hope it will help,