首页 \ 问答 \ 使用Objective-C打印多部分/表单数据(POST multipart/form-data with Objective-C/Swift)

使用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
更新时间:2023-08-20 08:08

最满意答案

看看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.

相关问答

更多
  • @ Paul的答案是好的,但也值得注意的是, url属性可以是一个函数。 在我看来(这只是意见,因为最终的结果是一样的),代码更清晰,如果更详细,如果你设置id在initialize和引用它在一个函数: var Messages = Backbone.Collection.extend({ initialize: function(models, options) { this.id = options.id; }, url: function() { return '/mess ...
  • 我能够找出问题,并决定在这里张贴,这样另一个人就不必像我一样继续抨击他们的头脑了。 在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 ...
  • 你有正确的想法。 在获取填充项目后执行初始设置时,addOne()将呈现单个项目。 您可以向集合事件添加侦听器以添加新项目。 Collection.Fetch通过向集合添加新模型并保留旧模型来执行您想要的操作(只要您不将{reset:true}标志作为参数传递) 因此,在您的视图中将侦听器添加到initialize挂钩 initialize: function() { this.listenTo(this.collection, "add", this.addOne) } 您可能希望在Xff模型上 ...
  • 我将假设您并不是指路由器中的new AuthorList ,而是new AvailableBookList 。 您的收藏中有两个问题: 在您的网址定义中, this指的是window对象。 您在构造函数中传递的id参数未应用于您的集合实例。 它仅适用于视图(不适用于模型或集合)。 要解决第一个问题,您可以使用函数来定义集合URL,这将使您进入正确的范围: AvailableBookList = Backbone.Collection.extend({ model: AvailableBook, ur ...
  • 如果你的代码真的如你的问题所示,问题是你在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 ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。