EADemo可以发送http请求

时间:2013-11-11 19:52:24

标签: iphone objective-c ios6 bluetooth external-accessory

有人可以建议是否可以修改EADemo来发送HTTP请求(自定义标题和正文)。在我正在进行的项目中,外部附件将使用http请求接收数据。

用于在EADemo上书写的方法是

- (void)writeData:(NSData *)data;

1 个答案:

答案 0 :(得分:0)

好的,所以我找到了一个我将要使用的示例,但我将使用POST而不是GET。以下是GET请求的示例:

- (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode {
NSLog(@"stream:handleEvent: is invoked...");

switch(eventCode) {
    case NSStreamEventHasSpaceAvailable:
    {
        if (stream == oStream) {
            NSString * str = [NSString stringWithFormat:
                @"GET / HTTP/1.0\r\n\r\n"];
            const uint8_t * rawstring =
                (const uint8_t *)[str UTF8String];
            [oStream write:rawstring maxLength:strlen(rawstring)];
            [oStream close];
        }
        break;
    }
    // continued ...
    }
}

https://developer.apple.com/library/ios/documentation/cocoa/Conceptual/Streams/Articles/NetworkStreams.html