I am trying to log in to my website (www.trailbehind.com) and then send a POST request to upload a file.
I tried implementing some code just to request the home page without authenticating, which I found here: http://developer.apple.com/documentation/Networking/Conceptual/CFNetwork/CFHTTPTasks/CFHTTPTasks.html#//apple_ref/doc/uid/TP30001132-CH5-DontLinkElementID_10
However, not even that code works, and I'm not sure what to do next. Here's the code I tried just to request the home page:
CFStringRef url = CFSTR("http://www.trailbehind.com/");
CFURLRef myURL = CFURLCreateWithString(kCFAllocatorDefault, url, NULL);
CFStringRef requestMethod = CFSTR("GET");
CFHTTPMessageRef myRequest = CFHTTPMessageCreateRequest(kCFAllocatorDefault, requestMethod, myURL, kCFHTTPVersion1_1);
CFStringRef bodyData = CFSTR(""); // Usually used for POST data
CFHTTPMessageSetBody(myRequest, bodyData);
CFStringRef headerFieldName = CFSTR("X-My-Favorite-Field");
CFStringRef headerFieldValue = CFSTR("Dreams");
CFHTTPMessageSetHeaderFieldValue(myRequest, headerFieldName, headerFieldValue);
CFDataRef mySerializedRequest = CFHTTPMessageCopySerializedMessage(myRequest);
//get the page
CFReadStreamRef myReadStream = CFReadStreamCreateForHTTPRequest(kCFAllocatorDefault, myRequest);
CFReadStreamOpen(myReadStream);
CFHTTPMessageRef myResponse = CFReadStreamCopyProperty(myReadStream, kCFStreamPropertyHTTPResponseHeader);
UInt32 myErrCode = CFHTTPMessageGetResponseStatusCode(myResponse);
NSLog(@"%@", myResponse);
CFRelease(myRequest);
CFRelease(myURL);
CFRelease(url);
CFRelease(mySerializedRequest);
myRequest = NULL;
mySerializedRequest = NULL;