[View]  [Edit]  [Lock]  [References]  [Attachments]  [History]  [Home]  [Changes]  [Search]  [Help] 

sample[jx8-android] httpPOST

Perform a POST request to server and print the result to the console.

Uploaded Image: alert.gifNote: this code needs edition to point to a real sample server
"POST to server sample"
| str options callback |
options := #host -> 'www.aServerAddress.com'
	,(#path -> '/')
	,(#port -> #1337)
	,(#method -> #POST).
callback := [:response|
	str := ''.
	NodeHTTPClientResponse @ response
	  on: #data do: [:chunk| str := str , chunk ];
	  on: #end do: [ self print: str ];
	  on: #error do: [:e| self print: 'Got error ',e#message ]
(NodeJS http
	request: options
	with: callback)
	write: 'hello world';