Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I create an HTTP connection and log in on the iPhone?
    primarykey
    data
    text
    <p>I am trying to log in to my website (www.trailbehind.com) and then send a POST request to upload a file.</p> <p>I tried implementing some code just to request the home page without authenticating, which I found here: <a href="http://developer.apple.com/documentation/Networking/Conceptual/CFNetwork/CFHTTPTasks/CFHTTPTasks.html#//apple_ref/doc/uid/TP30001132-CH5-DontLinkElementID_10" rel="nofollow noreferrer">http://developer.apple.com/documentation/Networking/Conceptual/CFNetwork/CFHTTPTasks/CFHTTPTasks.html#//apple_ref/doc/uid/TP30001132-CH5-DontLinkElementID_10</a></p> <p>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:</p> <pre><code>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; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload