[Pharo-project] curl / http request

Sven Van Caekenberghe sven at beta9.be
Sat Apr 23 21:27:23 CEST 2011


Hey Camillo,

On 23 Apr 2011, at 20:05, Camillo Bruni wrote:

> I am too dumb and there is too little documentation which is hard to find :).
> So can anyone tell me how I do the following bash thingy in pharo?
> 
> curl $URL --data-binary $SOME_FILE -H 'Content-type:application/json'
> 
> I don't manage to get this working properly. I guess HTTPSocket is the class to use...
> 
> thanks a lot
> camillo

Well, Zinc HTTP Components [1], of course:

| json entity |
json := (FileStream fileNamed: '/tmp/foo.json') contentsOfEntireFile.
entity := ZnEntity with: json type: ZnMimeType applicationJson. 
ZnClient post: 'http://example.com/foo' data: entity

This will return a ZnResponse, inspect it for more details.
There are many more options, but this is a simple example to get you started.

The source code should be your friend.

Sven

[1] http://homepage.mac.com/svc/Zinc-HTTP-Components





More information about the Pharo-project mailing list