开发者

Making an HTTP request in Pharo and getting the response headers

开发者 https://www.devze.com 2023-01-12 10:35 出处:网络
how can I make an HTTP request and get both the respons开发者_运维技巧e content and the response headers?Or using the new Zinc framework, something like:

how can I make an HTTP request and get both the respons开发者_运维技巧e content and the response headers?


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.


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


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号