6

how can I make an HTTP request and get both the response content and the response headers?

dave
  • 61
  • 2

4 Answers4

7

Or using the new Zinc framework, something like:

| response content headers |

response := ZnClient new 
    url: 'http://stackoverflow.com';
    get;
    response.

content := response contents.
headers := response headers.
martineg
  • 1,269
  • 13
  • 14
3

Probably the easiest is if you load WebClient from http://www.squeaksource.com/WebClient.

Lukas Renggli
  • 8,754
  • 23
  • 46
1

To install WebClient:

(Installer ss project: 'WebClient')
  install: 'WebClient-Core'

and then

response := WebClient httpGet: 'http://www.google.com/'.
headers := response headers. "An OrderedCollection of headername -> headervalue"
body := response content.
Frank Shearar
  • 17,012
  • 8
  • 67
  • 94
0

Or if you want to do something more with them, the seaside one-click image for pharo or squeak

Stephan Eggermont
  • 15,847
  • 1
  • 38
  • 65