iphone - NSURLRequest 设置 HTTP header

标签 iphone objective-c cocoa cocoa-touch ios

我需要为请求设置 HTTP header 。在 NSURLRequest 类的文档中,我没有找到任何关于 HTTP header 的信息。如何设置 HTTP header 以包含自定义数据?

最佳答案

您需要使用 NSMutableURLRequest

NSMutableURLRequest* request = [[[NSMutableURLRequest alloc] initWithURL:url]
                                autorelease];

[request setValue:VALUE forHTTPHeaderField:@"Field You Want To Set"];

或添加标题:

[request addValue:VALUE forHTTPHeaderField:@"Field You Want To Set"];

关于iphone - NSURLRequest 设置 HTTP header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4809047/

相关文章:

iphone - 对象警告 : "discard qualifiers from pointer target type"

iPhone sdk paypal 集成 API

iphone - 以编程方式取消 UIAlertView

objective-c - 当焦点位于字段上时删除的 NSTextField/NSSearchField 默认值

cocoa - NSDictionary DictionaryWithContentsOfURL 超时?

iPhone SDK - 将触摸从 UIViewController 转发到 subview

iphone - 如何改进 iPhone UI 自动化?

ios - 关闭 Presentation ViewController

javascript - pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);

xcode - 如何使用 Swift 打开我的 OSX 应用程序的父文件夹