ZnClient --data {}

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

ZnClient --data {}

Sabine Manaa
Hi ,

I want to write the following command in pharo:

"curl -v -X POST --data '{""email"":""mail@gmail.com"", ""password"":""geheim""}' -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: BEARER d0ae3333-eaad-4335-a64b-8903470baa9f' 'https://user.gini.net/api/users'"

The following does not work, response is
415 Unsupported Media Type text/html;charset=UTF-8 2341B
And I assume that it is the "--data {}" part, which is wrong.

        ^ZnClient new
                systemPolicy ;
                https;
                host: 'user.gini.net';
                path: 'api/users';
                headerAt: 'Content-Type' add: 'application/json';
                headerAt: 'Authorization' add: ('BEARER {1}' format: {self getAccessToken});
                headerAt: 'Accept' add: 'application/json';
                contents:'--data {"email":"mail@gmail.com", "password":"geheim"} ';
                post.

how can I put the --data  part into the request?

Regards
Sabine
Reply | Threaded
Open this post in threaded view
|

Re: ZnClient --data {}

NorbertHartl
Sabine,

you have double double quotes in your post data. If you use single quotes on the commandline the content is not interpreted and you are sending "" and that is not valid.

Norbert

> Am 05.03.2015 um 18:59 schrieb Sabine Manaa <[hidden email]>:
>
> Hi ,
>
> I want to write the following command in pharo:
>
> "curl -v -X POST --data '{""email"":""[hidden email]"",
> ""password"":""geheim""}' -H 'Content-Type: application/json' -H 'Accept:
> application/json' -H 'Authorization: BEARER
> d0ae3333-eaad-4335-a64b-8903470baa9f' 'https://user.gini.net/api/users'"
>
> The following does not work, response is
> 415 Unsupported Media Type text/html;charset=UTF-8 2341B
> And I assume that it is the "--data {}" part, which is wrong.
>
> ^ZnClient new
> systemPolicy ;
> https;
> host: 'user.gini.net';
> path: 'api/users';
> headerAt: 'Content-Type' add: 'application/json';
> headerAt: 'Authorization' add: ('BEARER {1}' format: {self
> getAccessToken});
> headerAt: 'Accept' add: 'application/json';
> contents:'--data {"email":"[hidden email]", "password":"geheim"} ';
> post.
>
> how can I put the --data  part into the request?
>
> Regards
> Sabine
>
>
>
> --
> View this message in context: http://forum.world.st/ZnClient-data-tp4809798.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>


Reply | Threaded
Open this post in threaded view
|

Re: ZnClient --data {}

Sven Van Caekenberghe-2
In reply to this post by Sabine Manaa
Basically, this is how you should do it (after loading NeoJSON):

ZnClient new
  https;
  host: 'user.gini.net';
  path: 'api/users';
  headerAt: 'Authorization' add: ('BEARER {1}' format: { #myToken });
  accept: ZnMimeType applicationJson;
  contentReader: [ :entity | NeoJSONReader fromString: entity contents ];
  contentWriter: [ :data | ZnEntity with: (NeoJSONWriter toString: data) type: ZnMimeType applicationJson];
  contents: { #email->'[hidden email]'. #password->'geheim' } asDictionary;
  post.

But I tried it and I got SSL errors, again.

This host/server is really weird (there is no Server header so I don't know which one it is), but it says that it will close the connection, but it keeps it open.

And again, this will probably work on Windows/Linux.

Sven

> On 05 Mar 2015, at 18:59, Sabine Manaa <[hidden email]> wrote:
>
> Hi ,
>
> I want to write the following command in pharo:
>
> "curl -v -X POST --data '{""email"":""[hidden email]"",
> ""password"":""geheim""}' -H 'Content-Type: application/json' -H 'Accept:
> application/json' -H 'Authorization: BEARER
> d0ae3333-eaad-4335-a64b-8903470baa9f' 'https://user.gini.net/api/users'"
>
> The following does not work, response is
> 415 Unsupported Media Type text/html;charset=UTF-8 2341B
> And I assume that it is the "--data {}" part, which is wrong.
>
> ^ZnClient new
> systemPolicy ;
> https;
> host: 'user.gini.net';
> path: 'api/users';
> headerAt: 'Content-Type' add: 'application/json';
> headerAt: 'Authorization' add: ('BEARER {1}' format: {self
> getAccessToken});
> headerAt: 'Accept' add: 'application/json';
> contents:'--data {"email":"[hidden email]", "password":"geheim"} ';
> post.
>
> how can I put the --data  part into the request?
>
> Regards
> Sabine
>
>
>
> --
> View this message in context: http://forum.world.st/ZnClient-data-tp4809798.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>


Reply | Threaded
Open this post in threaded view
|

Re: ZnClient --data {}

Sven Van Caekenberghe-2
With the following version:

===
Name: Zodiac-Core-SvenVanCaekenberghe.38
Author: SvenVanCaekenberghe
Time: 5 March 2015, 10:50:20.718425 pm
UUID: e3136feb-d3ad-4e3e-b844-464737f0b9ea
Ancestors: Zodiac-Core-TheIntegrator.37

Change the semantics of ZdcSimpleSocketStream>>#fillReadBuffer to simply return when ConnectionClosed is seen while waiting for data instead of letting the exception through

Patch ZdcSecureSocketStream>>#fillBytes:startingAt:count: again by ignoring all exceptions from the SSL plugin
===

it now works:

ZnClient new
 https;
 host: 'user.gini.net';
 path: 'api/users';
 headerAt: 'Authorization' add: ('BEARER {1}' format: { #myToken });
 accept: ZnMimeType applicationJson;
 contentReader: [ :entity | NeoJSONReader fromString: entity contents ];
 contentWriter: [ :data | ZnEntity with: (NeoJSONWriter toString: data) type: ZnMimeType applicationJson];
 contents: { #email->'[hidden email]'. #password->'geheim' } asDictionary;
 post.

 => a Dictionary('error'->'invalid_token' 'error_description'->'Invalid access token: myToken' )

This is experimental. We'll see what the CI says. And if it behaves the same on all platforms.

Sven

> On 05 Mar 2015, at 19:42, Sven Van Caekenberghe <[hidden email]> wrote:
>
> Basically, this is how you should do it (after loading NeoJSON):
>
> ZnClient new
>  https;
>  host: 'user.gini.net';
>  path: 'api/users';
>  headerAt: 'Authorization' add: ('BEARER {1}' format: { #myToken });
>  accept: ZnMimeType applicationJson;
>  contentReader: [ :entity | NeoJSONReader fromString: entity contents ];
>  contentWriter: [ :data | ZnEntity with: (NeoJSONWriter toString: data) type: ZnMimeType applicationJson];
>  contents: { #email->'[hidden email]'. #password->'geheim' } asDictionary;
>  post.
>
> But I tried it and I got SSL errors, again.
>
> This host/server is really weird (there is no Server header so I don't know which one it is), but it says that it will close the connection, but it keeps it open.
>
> And again, this will probably work on Windows/Linux.
>
> Sven
>
>> On 05 Mar 2015, at 18:59, Sabine Manaa <[hidden email]> wrote:
>>
>> Hi ,
>>
>> I want to write the following command in pharo:
>>
>> "curl -v -X POST --data '{""email"":""[hidden email]"",
>> ""password"":""geheim""}' -H 'Content-Type: application/json' -H 'Accept:
>> application/json' -H 'Authorization: BEARER
>> d0ae3333-eaad-4335-a64b-8903470baa9f' 'https://user.gini.net/api/users'"
>>
>> The following does not work, response is
>> 415 Unsupported Media Type text/html;charset=UTF-8 2341B
>> And I assume that it is the "--data {}" part, which is wrong.
>>
>> ^ZnClient new
>> systemPolicy ;
>> https;
>> host: 'user.gini.net';
>> path: 'api/users';
>> headerAt: 'Content-Type' add: 'application/json';
>> headerAt: 'Authorization' add: ('BEARER {1}' format: {self
>> getAccessToken});
>> headerAt: 'Accept' add: 'application/json';
>> contents:'--data {"email":"[hidden email]", "password":"geheim"} ';
>> post.
>>
>> how can I put the --data  part into the request?
>>
>> Regards
>> Sabine
>>
>>
>>
>> --
>> View this message in context: http://forum.world.st/ZnClient-data-tp4809798.html
>> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>>
>


Reply | Threaded
Open this post in threaded view
|

Re: ZnClient --data {}

Sabine Manaa
Hi Sven,

great - it seems to work. Thanks again!
I have another problem now which has to be checked with gini. 
I will come back to you if there is something open.
Will your versions be included in the configurationOf for the next versions?

@Norbert: I used the curl string as a comment in a method and forgot to remove the double quotation marks in my post. :-)

regards
Sabine

2015-03-05 22:46 GMT+01:00 Sven Van Caekenberghe-2 [via Smalltalk] <[hidden email]>:
With the following version:

===
Name: Zodiac-Core-SvenVanCaekenberghe.38
Author: SvenVanCaekenberghe
Time: 5 March 2015, 10:50:20.718425 pm
UUID: e3136feb-d3ad-4e3e-b844-464737f0b9ea
Ancestors: Zodiac-Core-TheIntegrator.37

Change the semantics of ZdcSimpleSocketStream>>#fillReadBuffer to simply return when ConnectionClosed is seen while waiting for data instead of letting the exception through

Patch ZdcSecureSocketStream>>#fillBytes:startingAt:count: again by ignoring all exceptions from the SSL plugin
===

it now works:

ZnClient new
 https;
 host: 'user.gini.net';
 path: 'api/users';
 headerAt: 'Authorization' add: ('BEARER {1}' format: { #myToken });
 accept: ZnMimeType applicationJson;
 contentReader: [ :entity | NeoJSONReader fromString: entity contents ];
 contentWriter: [ :data | ZnEntity with: (NeoJSONWriter toString: data) type: ZnMimeType applicationJson];
 contents: { #email->'[hidden email]'. #password->'geheim' } asDictionary;
 post.

 => a Dictionary('error'->'invalid_token' 'error_description'->'Invalid access token: myToken' )

This is experimental. We'll see what the CI says. And if it behaves the same on all platforms.

Sven

> On 05 Mar 2015, at 19:42, Sven Van Caekenberghe <[hidden email]> wrote:
>
> Basically, this is how you should do it (after loading NeoJSON):
>
> ZnClient new
>  https;
>  host: 'user.gini.net';
>  path: 'api/users';
>  headerAt: 'Authorization' add: ('BEARER {1}' format: { #myToken });
>  accept: ZnMimeType applicationJson;
>  contentReader: [ :entity | NeoJSONReader fromString: entity contents ];
>  contentWriter: [ :data | ZnEntity with: (NeoJSONWriter toString: data) type: ZnMimeType applicationJson];
>  contents: { #email->'[hidden email]'. #password->'geheim' } asDictionary;
>  post.
>
> But I tried it and I got SSL errors, again.
>
> This host/server is really weird (there is no Server header so I don't know which one it is), but it says that it will close the connection, but it keeps it open.
>
> And again, this will probably work on Windows/Linux.
>
> Sven
>
>> On 05 Mar 2015, at 18:59, Sabine Manaa <[hidden email]> wrote:
>>
>> Hi ,
>>
>> I want to write the following command in pharo:
>>
>> "curl -v -X POST --data '{""email"":""[hidden email]"",
>> ""password"":""geheim""}' -H 'Content-Type: application/json' -H 'Accept:

>> application/json' -H 'Authorization: BEARER
>> d0ae3333-eaad-4335-a64b-8903470baa9f' 'https://user.gini.net/api/users'"
>>
>> The following does not work, response is
>> 415 Unsupported Media Type text/html;charset=UTF-8 2341B
>> And I assume that it is the "--data {}" part, which is wrong.
>>
>> ^ZnClient new
>> systemPolicy ;
>> https;
>> host: 'user.gini.net';
>> path: 'api/users';
>> headerAt: 'Content-Type' add: 'application/json';
>> headerAt: 'Authorization' add: ('BEARER {1}' format: {self
>> getAccessToken});
>> headerAt: 'Accept' add: 'application/json';
>> contents:'--data {"email":"[hidden email]", "password":"geheim"} ';
>> post.

>>
>> how can I put the --data  part into the request?
>>
>> Regards
>> Sabine
>>
>>
>>
>> --
>> View this message in context: http://forum.world.st/ZnClient-data-tp4809798.html
>> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>>
>




If you reply to this email, your message will be added to the discussion below:
http://forum.world.st/ZnClient-data-tp4809798p4809834.html
To start a new topic under Pharo Smalltalk Users, email [hidden email]
To unsubscribe from Pharo Smalltalk Users, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: ZnClient --data {}

Sabine Manaa
Hi Sven,

I have one more question: how can I put a "--data-binary" part in the post? I tried like this below but I get a 401 Unauthorized error. I assume that my code below - the uploadEntityFrom: part -  is wrong. The path is correct, the file is there.

I want to write this in pharo: 
(Command line works)
"curl -v -X POST --data-binary '@/users/sabine/desktop/Belege/beleg1.jpg' -H 'Accept: application/vnd.gini.v1+json' -H 'Authorization: BEARER 0ae2963-eaad-4055-a64b-8903470baa9f' 'https://api.gini.net/documents'"

| path |
path := ZnFileSystemUtils fullNameFor: 'beleg1.jpg'.
^ ZnClient new
systemPolicy;
https;
host: 'api.gini.net';
path: 'documents';
headerAt: 'Accept' add: 'application/vnd.gini.v1+json';
headerAt: 'Authorization' add: ('BEARER {1}' format: {(self getAccessToken)});
uploadEntityFrom: path;
post

regards
Sabine

2015-03-06 4:56 GMT+01:00 Sabine Manaa <[hidden email]>:
Hi Sven,

great - it seems to work. Thanks again!
I have another problem now which has to be checked with gini. 
I will come back to you if there is something open.
Will your versions be included in the configurationOf for the next versions?

@Norbert: I used the curl string as a comment in a method and forgot to remove the double quotation marks in my post. :-)

regards
Sabine

2015-03-05 22:46 GMT+01:00 Sven Van Caekenberghe-2 [via Smalltalk] <[hidden email]>:
With the following version:

===
Name: Zodiac-Core-SvenVanCaekenberghe.38
Author: SvenVanCaekenberghe
Time: 5 March 2015, 10:50:20.718425 pm
UUID: e3136feb-d3ad-4e3e-b844-464737f0b9ea
Ancestors: Zodiac-Core-TheIntegrator.37

Change the semantics of ZdcSimpleSocketStream>>#fillReadBuffer to simply return when ConnectionClosed is seen while waiting for data instead of letting the exception through

Patch ZdcSecureSocketStream>>#fillBytes:startingAt:count: again by ignoring all exceptions from the SSL plugin
===

it now works:

ZnClient new
 https;
 host: 'user.gini.net';
 path: 'api/users';
 headerAt: 'Authorization' add: ('BEARER {1}' format: { #myToken });
 accept: ZnMimeType applicationJson;
 contentReader: [ :entity | NeoJSONReader fromString: entity contents ];
 contentWriter: [ :data | ZnEntity with: (NeoJSONWriter toString: data) type: ZnMimeType applicationJson];
 contents: { #email->'[hidden email]'. #password->'geheim' } asDictionary;
 post.

 => a Dictionary('error'->'invalid_token' 'error_description'->'Invalid access token: myToken' )

This is experimental. We'll see what the CI says. And if it behaves the same on all platforms.

Sven

> On 05 Mar 2015, at 19:42, Sven Van Caekenberghe <[hidden email]> wrote:
>
> Basically, this is how you should do it (after loading NeoJSON):
>
> ZnClient new
>  https;
>  host: 'user.gini.net';
>  path: 'api/users';
>  headerAt: 'Authorization' add: ('BEARER {1}' format: { #myToken });
>  accept: ZnMimeType applicationJson;
>  contentReader: [ :entity | NeoJSONReader fromString: entity contents ];
>  contentWriter: [ :data | ZnEntity with: (NeoJSONWriter toString: data) type: ZnMimeType applicationJson];
>  contents: { #email->'[hidden email]'. #password->'geheim' } asDictionary;
>  post.
>
> But I tried it and I got SSL errors, again.
>
> This host/server is really weird (there is no Server header so I don't know which one it is), but it says that it will close the connection, but it keeps it open.
>
> And again, this will probably work on Windows/Linux.
>
> Sven
>
>> On 05 Mar 2015, at 18:59, Sabine Manaa <[hidden email]> wrote:
>>
>> Hi ,
>>
>> I want to write the following command in pharo:
>>
>> "curl -v -X POST --data '{""email"":""[hidden email]"",
>> ""password"":""geheim""}' -H 'Content-Type: application/json' -H 'Accept:

>> application/json' -H 'Authorization: BEARER
>> d0ae3333-eaad-4335-a64b-8903470baa9f' 'https://user.gini.net/api/users'"
>>
>> The following does not work, response is
>> 415 Unsupported Media Type text/html;charset=UTF-8 2341B
>> And I assume that it is the "--data {}" part, which is wrong.
>>
>> ^ZnClient new
>> systemPolicy ;
>> https;
>> host: 'user.gini.net';
>> path: 'api/users';
>> headerAt: 'Content-Type' add: 'application/json';
>> headerAt: 'Authorization' add: ('BEARER {1}' format: {self
>> getAccessToken});
>> headerAt: 'Accept' add: 'application/json';
>> contents:'--data {"email":"[hidden email]", "password":"geheim"} ';
>> post.

>>
>> how can I put the --data  part into the request?
>>
>> Regards
>> Sabine
>>
>>
>>
>> --
>> View this message in context: http://forum.world.st/ZnClient-data-tp4809798.html
>> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>>
>



If you reply to this email, your message will be added to the discussion below:
http://forum.world.st/ZnClient-data-tp4809798p4809834.html
To start a new topic under Pharo Smalltalk Users, email [hidden email]
To unsubscribe from Pharo Smalltalk Users, click here.
NAML



View this message in context: Re: ZnClient --data {}

Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|

Re: ZnClient --data {}

Sven Van Caekenberghe-2
As far as I can see, that is correct.

If you do the following, you can see your file echoed:

'/tmp/foo.txt' asFileReference writeStreamDo: [ :out | out << '123456' ].

ZnClient new
  url: 'http://zn.stfx.eu/echo';
  uploadEntityFrom: '/tmp/foo.txt';
  post.

There is also #testUploadSmallDocument

Since the error is 401, it could be something else, no ? Maybe you cannot upload the same file twice ?

Try to inspect the request/response instance variables in the ZnClient object.

BTW, you can write

  accept: 'application/vnd.gini.v1+json';

Sven

> On 07 Mar 2015, at 13:15, Sabine Manaa <[hidden email]> wrote:
>
> Hi Sven,
>
> I have one more question: how can I put a "--data-binary" part in the post? I tried like this below but I get a 401 Unauthorized error. I assume that my code below - the uploadEntityFrom: part -  is wrong. The path is correct, the file is there.
>
> I want to write this in pharo:
> (Command line works)
> "curl -v -X POST --data-binary '@/users/sabine/desktop/Belege/beleg1.jpg' -H 'Accept: application/vnd.gini.v1+json' -H 'Authorization: BEARER 0ae2963-eaad-4055-a64b-8903470baa9f' 'https://api.gini.net/documents'"
>
> | path |
> path := ZnFileSystemUtils fullNameFor: 'beleg1.jpg'.
> ^ ZnClient new
> systemPolicy;
> https;
> host: 'api.gini.net';
> path: 'documents';
> headerAt: 'Accept' add: 'application/vnd.gini.v1+json';
> headerAt: 'Authorization' add: ('BEARER {1}' format: {(self getAccessToken)});
> uploadEntityFrom: path;
> post
>
> regards
> Sabine
>
> 2015-03-06 4:56 GMT+01:00 Sabine Manaa <[hidden email]>:
> Hi Sven,
>
> great - it seems to work. Thanks again!
> I have another problem now which has to be checked with gini.
> I will come back to you if there is something open.
> Will your versions be included in the configurationOf for the next versions?
>
> @Norbert: I used the curl string as a comment in a method and forgot to remove the double quotation marks in my post. :-)
>
> regards
> Sabine
>
> 2015-03-05 22:46 GMT+01:00 Sven Van Caekenberghe-2 [via Smalltalk] <[hidden email]>:
> With the following version:
>
> ===
> Name: Zodiac-Core-SvenVanCaekenberghe.38
> Author: SvenVanCaekenberghe
> Time: 5 March 2015, 10:50:20.718425 pm
> UUID: e3136feb-d3ad-4e3e-b844-464737f0b9ea
> Ancestors: Zodiac-Core-TheIntegrator.37
>
> Change the semantics of ZdcSimpleSocketStream>>#fillReadBuffer to simply return when ConnectionClosed is seen while waiting for data instead of letting the exception through
>
> Patch ZdcSecureSocketStream>>#fillBytes:startingAt:count: again by ignoring all exceptions from the SSL plugin
> ===
>
> it now works:
>
> ZnClient new
>  https;
>  host: 'user.gini.net';
>  path: 'api/users';
>  headerAt: 'Authorization' add: ('BEARER {1}' format: { #myToken });
>  accept: ZnMimeType applicationJson;
>  contentReader: [ :entity | NeoJSONReader fromString: entity contents ];
>  contentWriter: [ :data | ZnEntity with: (NeoJSONWriter toString: data) type: ZnMimeType applicationJson];
>  contents: { #email->'[hidden email]'. #password->'geheim' } asDictionary;
>  post.
>
>  => a Dictionary('error'->'invalid_token' 'error_description'->'Invalid access token: myToken' )
>
> This is experimental. We'll see what the CI says. And if it behaves the same on all platforms.
>
> Sven
>
> > On 05 Mar 2015, at 19:42, Sven Van Caekenberghe <[hidden email]> wrote:
> >
> > Basically, this is how you should do it (after loading NeoJSON):
> >
> > ZnClient new
> >  https;
> >  host: 'user.gini.net';
> >  path: 'api/users';
> >  headerAt: 'Authorization' add: ('BEARER {1}' format: { #myToken });
> >  accept: ZnMimeType applicationJson;
> >  contentReader: [ :entity | NeoJSONReader fromString: entity contents ];
> >  contentWriter: [ :data | ZnEntity with: (NeoJSONWriter toString: data) type: ZnMimeType applicationJson];
> >  contents: { #email->'[hidden email]'. #password->'geheim' } asDictionary;
> >  post.
> >
> > But I tried it and I got SSL errors, again.
> >
> > This host/server is really weird (there is no Server header so I don't know which one it is), but it says that it will close the connection, but it keeps it open.
> >
> > And again, this will probably work on Windows/Linux.
> >
> > Sven
> >
> >> On 05 Mar 2015, at 18:59, Sabine Manaa <[hidden email]> wrote:
> >>
> >> Hi ,
> >>
> >> I want to write the following command in pharo:
> >>
> >> "curl -v -X POST --data '{""email"":""[hidden email]"",
> >> ""password"":""geheim""}' -H 'Content-Type: application/json' -H 'Accept:
>
> >> application/json' -H 'Authorization: BEARER
> >> d0ae3333-eaad-4335-a64b-8903470baa9f' 'https://user.gini.net/api/users'"
> >>
> >> The following does not work, response is
> >> 415 Unsupported Media Type text/html;charset=UTF-8 2341B
> >> And I assume that it is the "--data {}" part, which is wrong.
> >>
> >> ^ZnClient new
> >> systemPolicy ;
> >> https;
> >> host: 'user.gini.net';
> >> path: 'api/users';
> >> headerAt: 'Content-Type' add: 'application/json';
> >> headerAt: 'Authorization' add: ('BEARER {1}' format: {self
> >> getAccessToken});
> >> headerAt: 'Accept' add: 'application/json';
> >> contents:'--data {"email":"[hidden email]", "password":"geheim"} ';
> >> post.
>
> >>
> >> how can I put the --data  part into the request?
> >>
> >> Regards
> >> Sabine
> >>
> >>
> >>
> >> --
> >> View this message in context: http://forum.world.st/ZnClient-data-tp4809798.html
> >> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
> >>
> >
>
>
>
> If you reply to this email, your message will be added to the discussion below:
> http://forum.world.st/ZnClient-data-tp4809798p4809834.html
> To start a new topic under Pharo Smalltalk Users, email [hidden email]
> To unsubscribe from Pharo Smalltalk Users, click here.
> NAML
>
>
> View this message in context: Re: ZnClient --data {}
>
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>


Reply | Threaded
Open this post in threaded view
|

Re: ZnClient --data {}

Sabine Manaa
Hi Sven,

thanks a lot, I am a big step further now. Without your help it would not be like that!

Regards
Sabine

2015-03-07 13:52 GMT+01:00 Sven Van Caekenberghe-2 [via Smalltalk] <[hidden email]>:
As far as I can see, that is correct.

If you do the following, you can see your file echoed:

'/tmp/foo.txt' asFileReference writeStreamDo: [ :out | out << '123456' ].

ZnClient new
  url: 'http://zn.stfx.eu/echo';
  uploadEntityFrom: '/tmp/foo.txt';
  post.

There is also #testUploadSmallDocument

Since the error is 401, it could be something else, no ? Maybe you cannot upload the same file twice ?

Try to inspect the request/response instance variables in the ZnClient object.

BTW, you can write

  accept: 'application/vnd.gini.v1+json';

Sven

> On 07 Mar 2015, at 13:15, Sabine Manaa <[hidden email]> wrote:
>
> Hi Sven,
>
> I have one more question: how can I put a "--data-binary" part in the post? I tried like this below but I get a 401 Unauthorized error. I assume that my code below - the uploadEntityFrom: part -  is wrong. The path is correct, the file is there.
>
> I want to write this in pharo:
> (Command line works)
> "curl -v -X POST --data-binary '@/users/sabine/desktop/Belege/beleg1.jpg' -H 'Accept: application/vnd.gini.v1+json' -H 'Authorization: BEARER 0ae2963-eaad-4055-a64b-8903470baa9f' 'https://api.gini.net/documents'"
>
> | path |
> path := ZnFileSystemUtils fullNameFor: 'beleg1.jpg'.
> ^ ZnClient new
> systemPolicy;
> https;
> host: 'api.gini.net';
> path: 'documents';
> headerAt: 'Accept' add: 'application/vnd.gini.v1+json';
> headerAt: 'Authorization' add: ('BEARER {1}' format: {(self getAccessToken)});
> uploadEntityFrom: path;
> post
>
> regards
> Sabine
>
> 2015-03-06 4:56 GMT+01:00 Sabine Manaa <[hidden email]>:

> Hi Sven,
>
> great - it seems to work. Thanks again!
> I have another problem now which has to be checked with gini.
> I will come back to you if there is something open.
> Will your versions be included in the configurationOf for the next versions?
>
> @Norbert: I used the curl string as a comment in a method and forgot to remove the double quotation marks in my post. :-)
>
> regards
> Sabine
>
> 2015-03-05 22:46 GMT+01:00 Sven Van Caekenberghe-2 [via Smalltalk] <[hidden email]>:
> With the following version:
>
> ===
> Name: Zodiac-Core-SvenVanCaekenberghe.38
> Author: SvenVanCaekenberghe
> Time: 5 March 2015, 10:50:20.718425 pm
> UUID: e3136feb-d3ad-4e3e-b844-464737f0b9ea
> Ancestors: Zodiac-Core-TheIntegrator.37
>
> Change the semantics of ZdcSimpleSocketStream>>#fillReadBuffer to simply return when ConnectionClosed is seen while waiting for data instead of letting the exception through
>
> Patch ZdcSecureSocketStream>>#fillBytes:startingAt:count: again by ignoring all exceptions from the SSL plugin
> ===
>
> it now works:
>
> ZnClient new
>  https;
>  host: 'user.gini.net';
>  path: 'api/users';
>  headerAt: 'Authorization' add: ('BEARER {1}' format: { #myToken });
>  accept: ZnMimeType applicationJson;
>  contentReader: [ :entity | NeoJSONReader fromString: entity contents ];
>  contentWriter: [ :data | ZnEntity with: (NeoJSONWriter toString: data) type: ZnMimeType applicationJson];
>  contents: { #email->'[hidden email]'. #password->'geheim' } asDictionary;
>  post.
>
>  => a Dictionary('error'->'invalid_token' 'error_description'->'Invalid access token: myToken' )
>
> This is experimental. We'll see what the CI says. And if it behaves the same on all platforms.
>
> Sven
>
> > On 05 Mar 2015, at 19:42, Sven Van Caekenberghe <[hidden email]> wrote:
> >
> > Basically, this is how you should do it (after loading NeoJSON):
> >
> > ZnClient new
> >  https;
> >  host: 'user.gini.net';
> >  path: 'api/users';
> >  headerAt: 'Authorization' add: ('BEARER {1}' format: { #myToken });
> >  accept: ZnMimeType applicationJson;
> >  contentReader: [ :entity | NeoJSONReader fromString: entity contents ];
> >  contentWriter: [ :data | ZnEntity with: (NeoJSONWriter toString: data) type: ZnMimeType applicationJson];
> >  contents: { #email->'[hidden email]'. #password->'geheim' } asDictionary;
> >  post.
> >
> > But I tried it and I got SSL errors, again.
> >
> > This host/server is really weird (there is no Server header so I don't know which one it is), but it says that it will close the connection, but it keeps it open.
> >
> > And again, this will probably work on Windows/Linux.
> >
> > Sven
> >
> >> On 05 Mar 2015, at 18:59, Sabine Manaa <[hidden email]> wrote:
> >>
> >> Hi ,
> >>
> >> I want to write the following command in pharo:
> >>
> >> "curl -v -X POST --data '{""email"":""[hidden email]"",
> >> ""password"":""geheim""}' -H 'Content-Type: application/json' -H 'Accept:
>
> >> application/json' -H 'Authorization: BEARER
> >> d0ae3333-eaad-4335-a64b-8903470baa9f' 'https://user.gini.net/api/users'"
> >>
> >> The following does not work, response is
> >> 415 Unsupported Media Type text/html;charset=UTF-8 2341B
> >> And I assume that it is the "--data {}" part, which is wrong.
> >>
> >> ^ZnClient new
> >> systemPolicy ;
> >> https;
> >> host: 'user.gini.net';
> >> path: 'api/users';
> >> headerAt: 'Content-Type' add: 'application/json';
> >> headerAt: 'Authorization' add: ('BEARER {1}' format: {self
> >> getAccessToken});
> >> headerAt: 'Accept' add: 'application/json';
> >> contents:'--data {"email":"[hidden email]", "password":"geheim"} ';
> >> post.
>
> >>
> >> how can I put the --data  part into the request?
> >>
> >> Regards
> >> Sabine
> >>
> >>
> >>
> >> --
> >> View this message in context: http://forum.world.st/ZnClient-data-tp4809798.html
> >> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
> >>
> >
>
>
>
> If you reply to this email, your message will be added to the discussion below:
> http://forum.world.st/ZnClient-data-tp4809798p4809834.html
> To start a new topic under Pharo Smalltalk Users, email [hidden email]
> To unsubscribe from Pharo Smalltalk Users, click here.
> NAML
>
>
> View this message in context: Re: ZnClient --data {}
>
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>





If you reply to this email, your message will be added to the discussion below:
http://forum.world.st/ZnClient-data-tp4809798p4810238.html
To start a new topic under Pharo Smalltalk Users, email [hidden email]
To unsubscribe from Pharo Smalltalk Users, click here.
NAML