Small query about ZnClient post - with "; " form values

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Small query about ZnClient post - with "; " form values

Tim Mackinnon
I was trying to automate posting some values to a website (I would use Stfx.eu but it doesn’t do syntax highlighting and only seems to work for quite small amounts).

Anyway the following code always seems to trim values that have a ; in them - and I’m wondering if I’m missing something - or if its the endpoint that has an issue (although curl seems to work fine).

content := 'hello world; hello'.
ZnClient new
  systemPolicy;
  beOneShot;
  url: 'http://dpaste.com/api/v2/';
        formAt: 'title' put: 'my; title';
        formAt: 'syntax' put: 'smalltalk';
        formAt: 'expiry_days' put: '5';
  formAt: 'content' put: content;
  post.

Tim
Reply | Threaded
Open this post in threaded view
|

Re: Small query about ZnClient post - with "; " form values

Sven Van Caekenberghe-2
Tim,

> On 17 May 2019, at 03:04, Tim Mackinnon <[hidden email]> wrote:
>
> I was trying to automate posting some values to a website (I would use Stfx.eu but it doesn’t do syntax highlighting and only seems to work for quite small amounts).

Hmm, it does highlighting (but it is far from perfect).

There is indeed a limit to the upload size, 2048 bytes.

I answered Ben for the same problem, I believe, the solution being

  http://ws.stfx.eu/QZTOS3HQAAPS

Regards,

Sven

> Anyway the following code always seems to trim values that have a ; in them - and I’m wondering if I’m missing something - or if its the endpoint that has an issue (although curl seems to work fine).
>
> content := 'hello world; hello'.
> ZnClient new
>  systemPolicy;
>  beOneShot;
>  url: 'http://dpaste.com/api/v2/';
> formAt: 'title' put: 'my; title';
> formAt: 'syntax' put: 'smalltalk';
> formAt: 'expiry_days' put: '5';
>  formAt: 'content' put: content;
>  post.
>
> Tim


Reply | Threaded
Open this post in threaded view
|

Re: Small query about ZnClient post - with "; " form values

Tim Mackinnon
Thanks for chipping in Sven - I’d asked Ben for some help as I’d seen him on discord - that solution does indeed work.

See: http://dpaste.com/218RW5G (which isn’t bad - not sure about he red boxes around things, but the smalltalk highlighting is quite good (pygments I think), although there is another one that exercism use - whose name evades me).

This same example doesn’t work on Stfx - I get a 400 error, which I assumed was size, although 2k should give you a decent chunk of text - but I guess showing a package of code or a stack trace does blow through that. Hence my investigation of other tools like dPaste, pastebin and paste.ee.

As a related question - how would I know to use #addPart: vs: #formAt: ?

As our questions indicated - formAt: works for most things until you hit fields with $; in them (which I was suprised wasn’t just encoded when sent in the form).

The docs at dPaste are quite minimal - http://dpaste.com/api/v2/ which is why I didn’t think of multi-part, so what would guide me down that route?

Tim 


On 17 May 2019, at 09:39, Sven Van Caekenberghe <[hidden email]> wrote:

Tim,

On 17 May 2019, at 03:04, Tim Mackinnon <[hidden email]> wrote:

I was trying to automate posting some values to a website (I would use Stfx.eu but it doesn’t do syntax highlighting and only seems to work for quite small amounts).

Hmm, it does highlighting (but it is far from perfect).

There is indeed a limit to the upload size, 2048 bytes.

I answered Ben for the same problem, I believe, the solution being

 http://ws.stfx.eu/QZTOS3HQAAPS

Regards,

Sven

Anyway the following code always seems to trim values that have a ; in them - and I’m wondering if I’m missing something - or if its the endpoint that has an issue (although curl seems to work fine).

content := 'hello world; hello'.
ZnClient new
systemPolicy;
beOneShot;
url: 'http://dpaste.com/api/v2/';
formAt: 'title' put: 'my; title';
formAt: 'syntax' put: 'smalltalk';
formAt: 'expiry_days' put: '5';
formAt: 'content' put: content;
post.

Tim



Reply | Threaded
Open this post in threaded view
|

Re: Small query about ZnClient post - with "; " form values

Sven Van Caekenberghe-2
Tim,

> On 17 May 2019, at 11:57, Tim Mackinnon <[hidden email]> wrote:
>
> Thanks for chipping in Sven - I’d asked Ben for some help as I’d seen him on discord - that solution does indeed work.
>
> See: http://dpaste.com/218RW5G (which isn’t bad - not sure about he red boxes around things, but the smalltalk highlighting is quite good (pygments I think), although there is another one that exercism use - whose name evades me).
>
> This same example doesn’t work on Stfx - I get a 400 error, which I assumed was size, although 2k should give you a decent chunk of text - but I guess showing a package of code or a stack trace does blow through that. Hence my investigation of other tools like dPaste, pastebin and paste.ee.

But these are different !

http://ws.stfx.eu > Getting Started Workspace

http://ws.stfx.eu/1WS4U

ZnClient
  new
  systemPolicy;
  beOneShot;
  url: 'http://ws.stfx.eu';
  contents: ('''I was created \{1\} ago'' format: \{ (DateAndTime now - (DateAndTime fromString: ''{1}'')) humanReadablePrintString \}.' format: { DateAndTime
 now });
  post.

http://ws.stfx.eu/B0065H9IDJC0

> As a related question - how would I know to use #addPart: vs: #formAt: ?

By knowing/understanding a bit more about HTTP ? ;-)

> As our questions indicated - formAt: works for most things until you hit fields with $; in them (which I was suprised wasn’t just encoded when sent in the form).

How so ? Can you give me something simple that I can run that exposes that issue ?

> The docs at dPaste are quite minimal - http://dpaste.com/api/v2/ which is why I didn’t think of multi-part, so what would guide me down that route?

That is their problem, they need to explain how their stuff works.

Using verbose mode in curl usually helps a lot too.

Sven

> Tim
>
>
>> On 17 May 2019, at 09:39, Sven Van Caekenberghe <[hidden email]> wrote:
>>
>> Tim,
>>
>>> On 17 May 2019, at 03:04, Tim Mackinnon <[hidden email]> wrote:
>>>
>>> I was trying to automate posting some values to a website (I would use Stfx.eu but it doesn’t do syntax highlighting and only seems to work for quite small amounts).
>>
>> Hmm, it does highlighting (but it is far from perfect).
>>
>> There is indeed a limit to the upload size, 2048 bytes.
>>
>> I answered Ben for the same problem, I believe, the solution being
>>
>>  http://ws.stfx.eu/QZTOS3HQAAPS
>>
>> Regards,
>>
>> Sven
>>
>>> Anyway the following code always seems to trim values that have a ; in them - and I’m wondering if I’m missing something - or if its the endpoint that has an issue (although curl seems to work fine).
>>>
>>> content := 'hello world; hello'.
>>> ZnClient new
>>> systemPolicy;
>>> beOneShot;
>>> url: 'http://dpaste.com/api/v2/';
>>> formAt: 'title' put: 'my; title';
>>> formAt: 'syntax' put: 'smalltalk';
>>> formAt: 'expiry_days' put: '5';
>>> formAt: 'content' put: content;
>>> post.
>>>
>>> Tim
>>
>>
>


Reply | Threaded
Open this post in threaded view
|

Re: Small query about ZnClient post - with "; " form values

Sven Van Caekenberghe-2


> On 17 May 2019, at 12:15, Sven Van Caekenberghe <[hidden email]> wrote:
>
>> As a related question - how would I know to use #addPart: vs: #formAt: ?
>
> By knowing/understanding a bit more about HTTP ? ;-)

As I wrote in my reply to Ben:

Although curl is powerful, well known and well supported, I would not say it is a great standard for interface design, it is way too complex.

Zn tries to approach HTTP from an object design standpoint. You pass along a ZnMultiPartFormDataEntity object that contains ZnMimeParts as entity to your POST request.

HTTP transfers resources or entities between a client and a server using a limited set of verbs (ZnMessage subclasses ZnRequest and ZnResponse). Headers (ZnHeaders) contain meta data about HTTP messages.

Simplified, with a GET you request a resource, with a DELETE you remove a resource, with POST you create a new resource and with PUT/PATCH you update an existing resource.

Resources/entities can be anything, they are described by mime types (ZnMimeType) and identified by URLs/URIs (ZnUrl).

Zn models them as subclasses of ZnEntity. The most fundamental ones are ZnStringEntity for text based data and ZnByteArrayEntity for binary data. ZnStreamEntity is a special variant that support streaming transfers.

From the world of HTML (not HTTP !), more specifically, Forms, there are 2 popular resources/entities: ZnApplicationFormUrlEncodedEntity and ZnMultiPartFormDataEntity. These have structure that is also exposed as an API - and for which there is some extra support in ZnClient.

Most real REST APIs use JSON or XML for their payloads (see the #forJsonREST method for example).

HTH,

Sven


Reply | Threaded
Open this post in threaded view
|

Re: Small query about ZnClient post - with "; " form values

Tim Mackinnon
In reply to this post by Sven Van Caekenberghe-2
Thanks Sven - I’ll ping the guy at dpaste and ask - I was just curious if I was missing something obvious in encoding… his docs are sparse.

Muy point about stfx vs dpaste is that the latter uses one of those js syntax highlighting libraries (not sure what you use) and so you get something that looks quite nice (not knocking stfx but maybe it could use one of them too) - but more critically (for me trying to help exercism users communicate on this forum to ask code questions), it doesn’t seem like I can store something like - http://dpaste.com/218RW5G (I get a 400, which I guess is the size limit, as smaller examples work - e.g. http://ws.stfx.eu/64XPQAYR2YTU

Tim

On 17 May 2019, at 11:15, Sven Van Caekenberghe <[hidden email]> wrote:

Tim,

On 17 May 2019, at 11:57, Tim Mackinnon <[hidden email]> wrote:

Thanks for chipping in Sven - I’d asked Ben for some help as I’d seen him on discord - that solution does indeed work.

See: http://dpaste.com/218RW5G (which isn’t bad - not sure about he red boxes around things, but the smalltalk highlighting is quite good (pygments I think), although there is another one that exercism use - whose name evades me).

This same example doesn’t work on Stfx - I get a 400 error, which I assumed was size, although 2k should give you a decent chunk of text - but I guess showing a package of code or a stack trace does blow through that. Hence my investigation of other tools like dPaste, pastebin and paste.ee.

But these are different !

http://ws.stfx.eu > Getting Started Workspace

http://ws.stfx.eu/1WS4U

ZnClient
 new
 systemPolicy;
 beOneShot;
 url: 'http://ws.stfx.eu';
 contents: ('''I was created \{1\} ago'' format: \{ (DateAndTime now - (DateAndTime fromString: ''{1}'')) humanReadablePrintString \}.' format: { DateAndTime
now });
 post.

http://ws.stfx.eu/B0065H9IDJC0

As a related question - how would I know to use #addPart: vs: #formAt: ?

By knowing/understanding a bit more about HTTP ? ;-)

As our questions indicated - formAt: works for most things until you hit fields with $; in them (which I was suprised wasn’t just encoded when sent in the form).

How so ? Can you give me something simple that I can run that exposes that issue ?

The docs at dPaste are quite minimal - http://dpaste.com/api/v2/ which is why I didn’t think of multi-part, so what would guide me down that route?

That is their problem, they need to explain how their stuff works.

Using verbose mode in curl usually helps a lot too.

Sven

Tim


On 17 May 2019, at 09:39, Sven Van Caekenberghe <[hidden email]> wrote:

Tim,

On 17 May 2019, at 03:04, Tim Mackinnon <[hidden email]> wrote:

I was trying to automate posting some values to a website (I would use Stfx.eu but it doesn’t do syntax highlighting and only seems to work for quite small amounts).

Hmm, it does highlighting (but it is far from perfect).

There is indeed a limit to the upload size, 2048 bytes.

I answered Ben for the same problem, I believe, the solution being

http://ws.stfx.eu/QZTOS3HQAAPS

Regards,

Sven

Anyway the following code always seems to trim values that have a ; in them - and I’m wondering if I’m missing something - or if its the endpoint that has an issue (although curl seems to work fine).

content := 'hello world; hello'.
ZnClient new
systemPolicy;
beOneShot;
url: 'http://dpaste.com/api/v2/';
formAt: 'title' put: 'my; title';
formAt: 'syntax' put: 'smalltalk';
formAt: 'expiry_days' put: '5';
formAt: 'content' put: content;
post.

Tim






Reply | Threaded
Open this post in threaded view
|

Re: Small query about ZnClient post - with "; " form values

Sven Van Caekenberghe-2


> On 17 May 2019, at 13:17, Tim Mackinnon <[hidden email]> wrote:
>
> Thanks Sven - I’ll ping the guy at dpaste and ask - I was just curious if I was missing something obvious in encoding… his docs are sparse.
>
> Muy point about stfx vs dpaste is that the latter uses one of those js syntax highlighting libraries (not sure what you use) and so you get something that looks quite nice (not knocking stfx but maybe it could use one of them too)

ws.stfx.eu uses https://highlightjs.org

> - but more critically (for me trying to help exercism users communicate on this forum to ask code questions), it doesn’t seem like I can store something like - http://dpaste.com/218RW5G (I get a 400, which I guess is the size limit, as smaller examples work - e.g. http://ws.stfx.eu/64XPQAYR2YTU

Yes, that is too much, 2.4KB > 2 KB.

I could update the limit a bit if you want, it just has to be small enough to protect the server.

Note that ws.stfx.eu (not plain stfx.eu) also has the nice property that you either get an HTML page or the raw text.

http://ws.stfx.eu/64XPQAYR2YTU
http://ws.stfx.eu/64XPQAYR2YTU?format=text

When the server detects a browser client, it will serve HTML, else it will server raw text.

'http://ws.stfx.eu/64XPQAYR2YTU' asUrl retrieveContents.

> Tim
>
>> On 17 May 2019, at 11:15, Sven Van Caekenberghe <[hidden email]> wrote:
>>
>> Tim,
>>
>>> On 17 May 2019, at 11:57, Tim Mackinnon <[hidden email]> wrote:
>>>
>>> Thanks for chipping in Sven - I’d asked Ben for some help as I’d seen him on discord - that solution does indeed work.
>>>
>>> See: http://dpaste.com/218RW5G (which isn’t bad - not sure about he red boxes around things, but the smalltalk highlighting is quite good (pygments I think), although there is another one that exercism use - whose name evades me).
>>>
>>> This same example doesn’t work on Stfx - I get a 400 error, which I assumed was size, although 2k should give you a decent chunk of text - but I guess showing a package of code or a stack trace does blow through that. Hence my investigation of other tools like dPaste, pastebin and paste.ee.
>>
>> But these are different !
>>
>> http://ws.stfx.eu > Getting Started Workspace
>>
>> http://ws.stfx.eu/1WS4U
>>
>> ZnClient
>>  new
>>  systemPolicy;
>>  beOneShot;
>>  url: 'http://ws.stfx.eu';
>>  contents: ('''I was created \{1\} ago'' format: \{ (DateAndTime now - (DateAndTime fromString: ''{1}'')) humanReadablePrintString \}.' format: { DateAndTime
>> now });
>>  post.
>>
>> http://ws.stfx.eu/B0065H9IDJC0
>>
>>> As a related question - how would I know to use #addPart: vs: #formAt: ?
>>
>> By knowing/understanding a bit more about HTTP ? ;-)
>>
>>> As our questions indicated - formAt: works for most things until you hit fields with $; in them (which I was suprised wasn’t just encoded when sent in the form).
>>
>> How so ? Can you give me something simple that I can run that exposes that issue ?
>>
>>> The docs at dPaste are quite minimal - http://dpaste.com/api/v2/ which is why I didn’t think of multi-part, so what would guide me down that route?
>>
>> That is their problem, they need to explain how their stuff works.
>>
>> Using verbose mode in curl usually helps a lot too.
>>
>> Sven
>>
>>> Tim
>>>
>>>
>>>> On 17 May 2019, at 09:39, Sven Van Caekenberghe <[hidden email]> wrote:
>>>>
>>>> Tim,
>>>>
>>>>> On 17 May 2019, at 03:04, Tim Mackinnon <[hidden email]> wrote:
>>>>>
>>>>> I was trying to automate posting some values to a website (I would use Stfx.eu but it doesn’t do syntax highlighting and only seems to work for quite small amounts).
>>>>
>>>> Hmm, it does highlighting (but it is far from perfect).
>>>>
>>>> There is indeed a limit to the upload size, 2048 bytes.
>>>>
>>>> I answered Ben for the same problem, I believe, the solution being
>>>>
>>>> http://ws.stfx.eu/QZTOS3HQAAPS
>>>>
>>>> Regards,
>>>>
>>>> Sven
>>>>
>>>>> Anyway the following code always seems to trim values that have a ; in them - and I’m wondering if I’m missing something - or if its the endpoint that has an issue (although curl seems to work fine).
>>>>>
>>>>> content := 'hello world; hello'.
>>>>> ZnClient new
>>>>> systemPolicy;
>>>>> beOneShot;
>>>>> url: 'http://dpaste.com/api/v2/';
>>>>> formAt: 'title' put: 'my; title';
>>>>> formAt: 'syntax' put: 'smalltalk';
>>>>> formAt: 'expiry_days' put: '5';
>>>>> formAt: 'content' put: content;
>>>>> post.
>>>>>
>>>>> Tim
>>>>
>>>>
>>>
>>
>>
>