【问题标题】:Making an HTTP request in Pharo and getting the response headers在 Pharo 中发出 HTTP 请求并获取响应标头
【发布时间】:2010-08-22 23:44:44
【问题描述】:

如何发出 HTTP 请求并获取响应内容和响应标头?

【问题讨论】:

    标签: http smalltalk squeak pharo


    【解决方案1】:

    或者使用新的Zinc framework,类似:

    | response content headers |
    
    response := ZnClient new 
        url: 'http://*.com';
        get;
        response.
    
    content := response contents.
    headers := response headers.
    

    【讨论】:

      【解决方案2】:

      可能最简单的方法是从http://www.squeaksource.com/WebClient 加载WebClient

      【讨论】:

      • WebClient 也有实际有用的文档!
      【解决方案3】:

      要安装 WebClient:

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

      然后

      response := WebClient httpGet: 'http://www.google.com/'.
      headers := response headers. "An OrderedCollection of headername -> headervalue"
      body := response content.
      

      【讨论】:

        【解决方案4】:

        或者如果你想用它们做更多的事情,pharosqueak 的海边一键图片

        【讨论】: