0

我正在尝试创建一个记录到服务器的方法,获取它找到的 json 文件,然后选择每个元素中的 4 个并将其发送到一个地址。当我只为发送链接中的每种格式提供一个已知的单个数据而不是一次应该选择每个格式的循环时,我的下面的代码似乎可以工作。我得到的错误是:instance of smallInteger did not understand #readStream。是什么导致了这个错误?我还能如何自动化这些请求?

1 to: 4 do: [ :each |
   each.
   a := ZnClient new.
   a get: 'https://MyServer/'.
   a headerAt: 'referer' put: 'https://MyServer' ;
     formAt: 'email' add: 'myEmail' ;
     formAt: 'password' add: 'MyPass'.
   a post.
   a get: 'https://MyServer/json'.

   data := NeoJSONReader fromString: a contents.
   list := data at: each.
   foo := list at: 'num'.
   poo := list at: 'name'.
				
   a get: 'https://MyServer/copy/', poo.
   a url: 'https://MyServer/send/'.
   a formAt: 'add' add: 'given address' ;
     formAt: 'nb_pic' add: foo ;
     formAt: 'identf' add: poo.

   a post.
   a get: 'https://MyServer/json' ]

4

2 回答 2

1

乍一看,语法没有错。
但看起来你没有得到你正在使用的框架的 API:你发送getpost消息而不知道他们每次发送它们时实际上会执行一个“http get”和“http post”。

所以,虽然它自己的“语法”没问题,但非常不正确的是你在做什么(我不明白这是什么)。看,这就是您的程序可以理解的方式:

4 timesRepeat: [
    "this will do a post" 
    ZnClient new
        url: 'https://MyServer/';
        headerAt: 'referer' put: 'https://MyServer';
        formAt: 'email' add: 'myEmail';
        formAt: 'password' add: 'MyPass';
        post.

    "this is a simple get"
    a := ZnClient get: 'https://MyServer/json'.
    data := NeoJSONReader fromString: a contents.
    list := data at:each.
    foo := list at:'num'.
    poo := list at:'name'.

    "this is another get that I don't know what's doing here"
    a := ZnClient get: 'https://MyServer/copy/', poo.

    "this is another post"
    a := ZnClient 
        url: 'https://MyServer/send/';
        formAt: 'add' add: 'given address';
        formAt: 'nb_pic' add:foo;
        formAt: 'identf' add: poo;
        post.

    "and finally, this is another get"
    ZnClient get: 'https://MyServer/json' ]

显然,该代码没有做你想做的事情:)

于 2018-02-06T09:32:16.500 回答
0

感谢@Carlo 提示,我发现错误消息:smallInteger 的实例不理解 #readStream 是由于从 poo 和 foo 收集的值。

    list := data at:each.
    foo := list at:'num'. "Here and integer"
    poo := list at:'name'."Here a byteString"

实际上,表单操作需要一个如图所示的键和值,但是该值必须是一个字符串,我只是用 poo 和 foo 替换来添加,我做得不对:

    formAt: 'nb_pic' add:foo;
    formAt: 'identf' add: poo;

因此我需要将 foo 和 poo asString 转换,现在它工作正常。谢谢

于 2018-02-07T13:00:02.870 回答