1

私はRestKitをチェックアウトしており、GETは機能します

@client.get("/?amount=5", delegate:self)

POST を作成して結果を受け取る方法を知っている人はいますか?

ドキュメントは、それが次のように見えると述べています-

@client.post("/ask", params:@paramvar, delegate:self)

@paramvar は何をカプセル化しますか? 私はそれを配列、ハッシュ、さらには nil として試しましたが、結果は得られませんでした。

4

3 に答える 3

6

プチプチ ライブラリを見てみましょう。これには、非常に優れた HTTP ヘルパーが含まれています。

http://bubblewrap.io/

于 2012-10-31T16:19:03.127 に答える
3

RubyMotion_Cookbook で例を見つけました。

https://github.com/IconoclastLabs/rubymotion_cookbook/tree/master/ch_8/06_sendinghttppost

class AppDelegate
  def application(application, didFinishLaunchingWithOptions:launchOptions)
    @window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
    @window.rootViewController = RootController.new

    url_string = "http://rubymotion-cookbook.herokuapp.com/post"
    post_body = "bodyParam1=BodyValue1&bodyParam2=BodyValue2"

    url = NSURL.URLWithString(url_string)
    request = NSMutableURLRequest.requestWithURL(url)
    request.setTimeoutInterval(30)
    request.setHTTPMethod("POST")
    request.setHTTPBody(post_body.to_s.dataUsingEncoding(NSUTF8StringEncoding))
    queue = NSOperationQueue.alloc.init

    NSURLConnection.sendAsynchronousRequest(request,
      queue: queue,
      completionHandler: lambda do |response, data, error|
        if(data.length > 0 && error.nil?)
          html = NSString.alloc.initWithData(data, encoding: NSUTF8StringEncoding)
          p "HTML = #{html}"
        elsif( data.length == 0 && error.nil? )
          p "Nothing was downloaded"
        elsif(!error.nil?)
          p "Error: #{error}"
        end
      end
    )


    @window.makeKeyAndVisible
    true
  end
end
于 2012-07-12T05:27:35.700 に答える
0

ソース: https://github.com/rubymotion/BubbleWrap

インストール:-
コンソールで「gem install bubble-wrap」を実行するか、Gemfile で「gem bubble-wrap」を指定します

「app_delegate.rb」ファイルに追加する行 (このにより、Bubblewrap API はアプリ全体で使用可能になります):-
「bubble-wrap/http」が必要です

構文のサンプル コード:-
BW::HTTP.get(" https://api.github.com/users/mattetti ", {credentials: {username: 'matt', password: 'aimonetti'}}) do |response | | p response.body.to_str # レスポンスのボディ end を出力します

于 2013-08-08T17:43:27.980 に答える