Ну, я смог сделать GET / POST, используя обычный CFSocket.
-(bool) sendHTTPHeader{
NSMutableString* requestString = [[NSMutableString alloc] init];
NSString *pathString = [NSString stringWithFormat:@"/remote_function.jsp?argument1=%@&argument2=%@",arg1,arg2 ];
[requestString appendFormat:@"GET %@ HTTP/1.x\r\n",pathString];
[requestString appendFormat:@"HOST:%@",your_host_here];
[requestString appendFormat:@"User-Agent:any\r\n"];
[requestString appendFormat:@"Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n\r\n"];
/*If there are more parameters requested by server, put them here..*/
const char* sendString = [requestString UTF8String];
CFDataRef data = CFDataCreate(NULL, (const UInt8*)sendString, strlen(sendString));
CFSocketError err = CFSocketSendData(clientSocket, NULL, data, 0);
if (err != kCFSocketSuccess) {
NSLog(@"Error in sending data to the server");
CFRelease(data);
return FALSE;
}
[requestString release];
CFRelease(data);
return TRUE;
}
Теперь в функции обратного вызова сокета вы можете прочитать ответ http. Надеюсь, это кому-нибудь поможет.
void socketCallback(CFSocketRef socket,CFSocketCallBackType type,CFDataRef address,const void *data,void *info){
if (type == kCFSocketDataCallBack) {
NSData *nsData = (NSData *)data;
if ([nsData length] == 0) {
NSLog(@"Connection dropped by remote socket");
return;
}
//Control reaches here when there is a chunk of data to read
CFDataRef df = (CFDataRef) data;
int len = CFDataGetLength(df);
CFRange range = CFRangeMake(0,len);
UInt8 buffer[len+1];
if(len <= 0) {
NSLog(@"No data read");
return;
}
memset((void*)buffer,0,sizeof(buffer));
CFDataGetBytes(df, range, buffer);
NSString *byteString = [[NSString alloc] initWithBytes:buffer length:len encoding:NSUTF8StringEncoding];
NSLog(@"byte string is : %@",byteString);
[byteString release];
}
}