Mostrando entradas con la etiqueta web. Mostrar todas las entradas
Mostrando entradas con la etiqueta web. Mostrar todas las entradas

martes, 16 de octubre de 2018

Pharo Script of the Day: Find your IP address

I' back :)

Today let's update the PSotD blog with a script to find your IP address using Zinc HTTP Components. Credits also to Sven Van Caekenberghe which helped me to figure out why Zn was getting a 403

ZnClient new
   systemPolicy;
   beOneShot;
   url: 'http://ifconfig.me/ip';
   accept: ZnMimeType textPlain;
   headerAt: 'User-Agent' put: 'curl/7.54.0';
   timeout: 6000;
   get.

miércoles, 26 de septiembre de 2018

Pharo Script of the Day: Replay cookies with Zinc HTTP components

For this one we will use a browser plug-in called CookieBro. It will allow us to import existing cookies from a web browser session into Pharo Smalltalk just using the Zinc HTTP Components, which are by default installed in the image, and NeoJSON. Let's assume then we have exported the cookies in a "cookiebro-cookies.json" file, the script translates the cookie's JSON format into a name–value pair (cookie crumb) suitable for a ZnCookieJar object. And it just requires you to enter the website you want to access:

| jar cookiesFile client |
jar := ZnCookieJar new.
cookiesFile := 'cookiebro-cookies.json'.
(NeoJSONReader fromString: cookiesFile asFileReference) do: [ : d |
jar add: (ZnCookie fromString: (String streamContents: [ : stream |
 d associationsDo: [ : assoc |
  stream 
   nextPutAll: assoc key asString;
   nextPut: $=;
   nextPutAll: assoc value asString;
   nextPut: $; ].
  stream skip: -1 ] )) ].
client := ZnClient new
 beOneShot;
 timeout: 5000;
 numberOfRetries: 0; 
 url: 'https://...';
 ifFail: [ : ex | self halt. ].
client session cookiejar: jar.
client get

Of course if you have any suggestions I will be glad to read them in the comments.

jueves, 16 de abril de 2015

Iliad 0.9.4 is out

Installation

I have updated the Iliad Web Application Server to load properly in Pharo 4 (good tutorials here and here). All tests passes. As usuall you can load it from the Configuration Browser or by evaluating the expression:
Gofer it
 smalltalkhubUser: 'hernan' project: 'Iliad';
 configuration;
 loadStable

Usage

Start the Iliad Web Application Server in port 8888 using the Comanche/Kom Web Server adapter:
IliadKom startOn: 8888.
And point your browser to: http://localhost:8888/ Stop all servers:
IliadKom stop.
If things go bad you can start Iliad in Debug Mode:
IliadKom startDebugOn: 8888.
and enjoy the opened Debugger in the signaler method when an exception is signaled.

Changes

  • Use the Grease latest stable version which includes a fix of the #next: method in GRPharoUtf8CodecStream (thanks Benoit Astruc)
  • Added ILTempFile helper methods (#printOn: and #extension).
  • Added ILCaptionElement and ILDatalistElement (thanks Benoit Astruc).
  • Added methods to start Comanche in debug and verbose mode.
  • Changed HttpService name to be more descriptive in the Process list.
  • Removed versions for GemStone and Squeak in ConfigurationOf (will add later after check)
  • Use convertToEncoding: instead of #decode: to patch the Invalid UTF-8 bug.
  • Replaced Pharo 4 deprecated TimeStamp with DateAndTime.
  • Replaced senders of Pharo 4 deprecated #displayString with #asString.
  • Updated acknowledgements windows and text.