【问题标题】:problem in setting parameters for NSMutableURLRequest ( POST request)为 NSMutableURLRequest(POST 请求)设置参数时出现问题
【发布时间】:2011-06-02 15:52:29
【问题描述】:

正在使用类方法为 NSMutableURLRequest(POST) 设置参数(键值对 - 用户名、密码、电子邮件 ID)

 + (void)setProperty:(id)value forKey:(NSString *)key inRequest:(NSMutableURLRequest *)request

并使用 sendSynchronous 请求服务器。

但在服务器端,参数为空。

请给我一些其他新的解决方案???

【问题讨论】:

    标签: iphone objective-c http post http-post


    【解决方案1】:

    使用ASIFormDataRequest。它的-setPostValue:forKey: 方法使得将数据作为application/x-www-urlformencoded 或multipart/form-data 发布非常简单。

    如果您想改用NSURLRequest,请查看the OAuthConsumer project 以获取使用application/x-www-form-urlencoded 的示例。首先阅读NSMutableURLRequest+Parameters.m and go from there. For sending data asmultipart/form-datausingNSURLRequest`中的-setParameters:,请参阅Facebook的FBRequest。

    +[NSURLProtocol setProperty:forKey:inRequest:] 旨在用于扩展 URL 加载系统以支持其他协议:

    需要扩展NSURLRequest 和NSMutableURLRequest 功能的协议实现者[通过在这些类上提供类别] 可以使用NSURLProtocol 的类方法propertyForKey:inRequest: 和@ 存储和检索特定于协议的请求数据987654339@。 (here)

    【讨论】:

    • @yokks 编辑了使用NSURLRequest的示例链接。
    猜你喜欢
    • 2013-09-05
    • 2017-06-08
    • 1970-01-01
    • 1970-01-01
    • 2021-09-06
    • 1970-01-01
    • 2020-10-17
    • 1970-01-01
    • 2016-08-11
    相关资源
    最近更新 更多