ios - xcode 的 HTTP 发布示例

标签 ios xcode http

我需要一个简单的例子,我们向服务器发送一些 HTTP 请求。而且我还需要向该 HTTP 帖子添加一些 header 。我试过发布 HTTP 帖子,但对在请求中添加 header 有点困惑。我必须在 HTTP Post 中添加任何必填字段/HEADER 吗??

最佳答案

假设你有一个名为 theRequestNSURLRequest

您将请求类型配置为 POST with

[theRequest setHTTPMethod:@"POST"];

对于 header ,您将值添加到 header 中,您将它们作为键值对添加:

[theRequest setValue:authorizationString forKey:@"Authorization"];

它为 Authorization header 设置 authorizationString

关于ios - xcode 的 HTTP 发布示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9080412/

相关文章:

ios - 如何在 Xcode 7 中启用_BITCODE?

android - 适用于 Android 的 Unity Google Play 游戏,Xcode 中的 +200 错误

ios - 在 iOS 上使用 Core Graphics 将 PDF 渲染为图像的颜色准确性问题

ios - swift 'does not have a member named'

ios - 为什么我不能摆脱 libstdc++?

c# - 当我从 HTTP 重定向到 HTTPS 时,用户必须重新登录

perl - 如何在 Perl 中获取 HTTP 状态和 Location header ?

ios - 当 UIWebView 完成加载时,如何强制重新布局 UITableViewCell?

Swift:使用推送 View Controller 改变方向

http - 是 http ://example/resource# and http://example/resource equivalent?