![](/img/trans.png)
[英]What is the origin of the parmname: value syntax for passing paramters?
[英]What could be wrong with this syntax pharos?
我試圖創建一種方法登錄到服務器,獲取它找到的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' ]
乍一看,語法沒有錯。
但是看起來您沒有獲得所使用框架的API:您發送get
和post
消息時並不了解每次發送它們實際上都會執行“ 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' ]
顯然,該代碼沒有按照您想要的去做:)
我想出了@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轉換,現在可以正常工作了。 謝謝
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.