使用Objective-C打印多部分/表单数据(POST multipart/form-data with Objective-C/Swift)
所以这个HTML代码为我提供了正确格式的数据。
<form action="https://www.example.com/register.php" method="post" enctype="multipart/form-data"> Name: <input type="text" name="userName"><BR /> Email: <input type="text" name="userEmail"><BR /> Password: <input type="text" name="userPassword"><BR /> Avatar: <input type="file" name="avatar"><BR /> <input type="submit"> </form>
我已经研究了很多关于如何在iOS上进行多部分/表单数据POST的文章,但是没有一个真正解释如果有正常的参数以及文件上传,该怎么办。
你可以帮助我的代码来发布在Obj-C?
谢谢!
So this HTML code submits the data in the correct format for me.
<form action="https://www.example.com/register.php" method="post" enctype="multipart/form-data"> Name: <input type="text" name="userName"><BR /> Email: <input type="text" name="userEmail"><BR /> Password: <input type="text" name="userPassword"><BR /> Avatar: <input type="file" name="avatar"><BR /> <input type="submit"> </form>
I've looked into a good number of articles on how to do a multipart/form-data POST on iOS, but none really explain what to do if there were normal parameters as well as the file upload.
Could you please help me with the code to POST this in Obj-C?
Thanks!
原文:https://stackoverflow.com/questions/24250475
最满意答案
看看get方法,可能有一些帮助:)
http://backbonejs.org/#Collection-get
get collection.get(id)
从一个集合中获取一个模型,由一个id,一个cid指定,或者通过传递一个模型。Take a look at the get method, it may be of some help :)
http://backbonejs.org/#Collection-get
get collection.get(id)
Get a model from a collection, specified by an id, a cid, or by passing in a model.
相关问答
更多-
Backbone.js集合选项(Backbone.js collection options)[2023-01-02]
@ Paul的答案是好的,但也值得注意的是, url属性可以是一个函数。 在我看来(这只是意见,因为最终的结果是一样的),代码更清晰,如果更详细,如果你设置id在initialize和引用它在一个函数: var Messages = Backbone.Collection.extend({ initialize: function(models, options) { this.id = options.id; }, url: function() { return '/mess ... -
Backbone.js集合(Backbone.js Collection)[2022-01-28]
我能够找出问题,并决定在这里张贴,这样另一个人就不必像我一样继续抨击他们的头脑了。 在PostView视图类中,我必须在collection.fetch()中包装下划线.each我注意到模型是在集合回调属性中返回的。 所以我做的是添加以下内容; render:function () { this.$el.html(''); this.$el.append(this.template(this)); that = this; this.collection.fetch({s ... -
看看get方法,可能有一些帮助:) http://backbonejs.org/#Collection-get get collection.get(id) 从一个集合中获取一个模型,由一个id,一个cid指定,或者通过传递一个模型。 Take a look at the get method, it may be of some help :) http://backbonejs.org/#Collection-get get collection.get(id) Get a model from a c ...
-
您的parse()函数不应该set()任何东西,它更好的做法只是返回属性,Backbone将负责设置它。 例如 parse: function(response) { response.summaryList = new JobSummaryList(response.summaryList); return response; } 从parse()返回的任何东西都传递给set() 。 不返回任何东西(就像返回undefined )与调用set(undefined) ,这可能导致它不通过验 ...
-
我找到了解决方案。 我的观点是将danceAssignments集合渲染为SyllabusView的一部分。 一旦我添加了一个带有集合的DanceListView作为其数据,并让它渲染DanceViews而不是SyllabusView,它就会使舞蹈开始正确排序,其他一些非常奇怪的行为也会被解决。 I found the solution. My views were rendering the danceAssignments collection as part of SyllabusView. Once ...
-
有一个位于Backbone.js之上的JavaScript库,它可以减少您必须编写的样板代码量,并且它们具有最适合嵌套集合的CompositeView。 我已经包含了文档和讨论使用它的文章。 Marionette CompositeView文档 Marionette CompositeView文章 There is a JavaScript library that sits on top of Backbone.js that reduces the amount of boiler plate code ...
-
Backbone.js:仅从JSON集合提取中添加新模型(Backbone.js: Adding just the new models from JSON collection fetch)[2021-12-23]
你有正确的想法。 在获取填充项目后执行初始设置时,addOne()将呈现单个项目。 您可以向集合事件添加侦听器以添加新项目。 Collection.Fetch通过向集合添加新模型并保留旧模型来执行您想要的操作(只要您不将{reset:true}标志作为参数传递) 因此,在您的视图中将侦听器添加到initialize挂钩 initialize: function() { this.listenTo(this.collection, "add", this.addOne) } 您可能希望在Xff模型上 ... -
Backbone.js集合url(Backbone.js collection url)[2021-11-02]
我将假设您并不是指路由器中的new AuthorList ,而是new AvailableBookList 。 您的收藏中有两个问题: 在您的网址定义中, this指的是window对象。 您在构造函数中传递的id参数未应用于您的集合实例。 它仅适用于视图(不适用于模型或集合)。 要解决第一个问题,您可以使用函数来定义集合URL,这将使您进入正确的范围: AvailableBookList = Backbone.Collection.extend({ model: AvailableBook, ur ... -
无法从模板中访问Backbone.js集合/模型(Cannot access Backbone.js collection / models from with in template)[2022-08-08]
如果你的代码真的如你的问题所示,问题是你在fetch返回之前呈现视图,这就是你的集合为空的原因。 fetch需要一些时间才能返回,但是你在调用fetch后立即调用render 。 在fetch函数的成功处理程序中调用render ,或将render绑定到集合的reset事件。 If your code is truly as shown in your question, the issue is that you are rendering the view before the fetch has re ... -
collection.create ,因为与服务器请求相关的所有方法确实是异步的。 在您的情况下,您可以收听同步事件以获得所需的结果。 来自http://backbonejs.org/#Collection-create 创建模型将导致在集合上触发立即“添加”事件,以及在服务器上成功创建模型后的“同步”事件。 例如: resp.on('sync', function(model) { console.dir( resp ); console.dir( resp.get("strt") ); co ...