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

sample[jx8-android] httpGET

Perform a GET request to aleReimondo's folder and print the result to the console.

"Perform a GET request to aleReimondo's folder"
| str options callback |
options := #host -> 'u8.smalltalking.net'
	,(#path -> '/profile/aleReimondo/').
callback := [:res||response|
	response := NodeHTTPClientResponse @ res.
	"self print: 'statusCode=',response statusCode."
	str := ''.
	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) end



"Get contents of UI8 source file"
| str callback |
callback := [:res||response|
	response := NodeHTTPClientResponse @ res.
	response statusCode = 200 ifFalse: [
		self error: 'File not found'
	].
	str := ''.
	response
	  on: #data do: [:chunk| str := str , chunk ];
	  on: #end do: [ self print: str ]
].
(NodeJS http
	request: 'http://u8.smalltalking.net/profile/aleReimondo/WI8/UI8.st'
	with: callback) end