Category Archives: Mac

Using netcat to catch request data from cUrl

I recently needed to compare post data from cUrl and webMethods 9.9. The cUrl request worked like a charm but the same request from the pub.client.http service failed to be recognized by the consumer. I then got a tip from a colleague to use the netcat program to catch the output from both programs and compare the results. Here is how I did:

Start a listener on an non-privileged port eg. 8000

nc -l 8000

With this running in one console window we switch to another and run a curl command eg.

curl -F attachment=@file.csv http://localhost:8000

The file.csv in this example is a MIME message

The message is now captured and written to the console like this:

POST / HTTP/1.1
Host: localhost:8000
User-Agent: curl/7.54.0
Accept: */*
Content-Length: 382
Expect: 100-continue
Content-Type: multipart/form-data; boundary=--10e698fa110003d5

----10e698fa110003d5
Content-Disposition: form-data; name="attachment"; filename="file.csv"
Content-Type: application/octet-stream

HELLO WORLD

----10e698fa110003d5--

TIP 1:
Start nc like this:

 
nc -l localhost 8000 &

Now run curl like this:

 
curl --proxy localhost:8000 --silent --max-time 1 http://blog.niklasottosson.com

And you will catch one and one only request

TIP 2:
Start nc like this:

nc -l loclahost 8000 > request.txt 

And you will catch the request in a file called request.txt

Tested on OSX 10.13.6 and cUrl 7.54.0

Telnet in OSX High Sierra?

Yes they decided to remove the Telnet client in High Sierra (10.13). So, what to do? I have found 3 solutions that have worked for my machines

  • Move your old telnet client from /usr/bin on a Sierra machine and to /usr/local/bin on you High Sierra machine
  • Install the ‘inetutils’ package from Macports (sudo port install inetutils) . This contains a Telnet client, among other utilities
  • Switch to the built in nc (netcat) client on High Sierra. Netcat seems to be similar to Telnet but I have only done some simple tests like connecting

Charset problem in Play framework after upgrading OSX

This is such a strange problem that I just have to write it down for future reference.
Involved systems:
* One Ubuntu 14.04.2 LTS on AWS (Amazon Web Services)
* One MacBook Pro 2010 with 10.7.5 with iTerm 2.1.1
* One MacBook Pro 2015 with 10.10.3 with iTerm 2.1.1
* One Play framework 2.3 application

Problem description:
After starting the Play application with the MacBook that has the 10.10.3 version all files that were written to disk had all non-ascii characters shown as ??. When starting the Play application with the old computer (10.7.5) these characters where displayed correctly.

After quite a lot of trial-and-error I found that the command ‘locale’ on the remote AWS server complained about:
“locale: Cannot set LC_CTYPE to default locale: No such file or directory”
“locale: Cannot set LC_ALL to default locale: No such file or directory”
when using the newer computer but not with the old

Solution:
The ‘locale’ command error lead me to the following solution in iTerm:
Untick the Terminal option “Set locale variables automaticly” in Preference
QQ20140113-3

This option is AFAIK default on in iTerm

After this was done the ‘locale’ error was gone and all files had the correct charset