• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Submitting a web form?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Submitting a web form?


  • Subject: Re: Submitting a web form?
  • From: email@hidden
  • Date: Wed, 10 Nov 2010 16:28:18 -0700

- (int)HTTPPostProcess:(Register *)reg host:(NSString*)host cgi: (NSString*)cgi
{
CFHTTPMessageRef request;
CFStreamClientContext ctxt = {0, self, NULL, NULL, NULL};
NSString* url_string = [host stringByAppendingString:cgi];
url_string = [@"http://"; stringByAppendingString:url_string];

NSURL* url;
NSData* data;


    // Don't fetch if there is a fetch in progress.
    if(_stream) return kBusy;

    // Create a new url based upon url_string
    url = [NSURL URLWithString: url_string];

// Set the POST data
NSString *postData = [reg getRegData]; // (see below for getRegData)


// Prepare the POST data
data = [postData dataUsingEncoding: NSUTF8StringEncoding];
if(!data) return kBadData;


// Create a new HTTP request.
request = CFHTTPMessageCreateRequest(kCFAllocatorDefault, CFSTR("POST"), (CFURLRef)url, kCFHTTPVersion1_1);
if (!request) return kRequestFailed;

// Set the body.
CFHTTPMessageSetBody(request, (CFDataRef)data);

// Create the stream for the request.
_stream = CFReadStreamCreateForHTTPRequest(kCFAllocatorDefault, request);


    // Release the request.  The fetch should've retained it if it
    // is performing the fetch.
    CFRelease(request);

    // Make sure it succeeded.
    if (!_stream) return kStreamFailed;

// Set the client
if (!CFReadStreamSetClient(_stream, kNetworkEvents, ReadStreamClientCallBack, &ctxt)) {
CFRelease(_stream);
_stream = NULL;
return kStreamClientFailed;
}


// Schedule the stream
CFReadStreamScheduleWithRunLoop(_stream, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);


// Start the HTTP connection
if (!CFReadStreamOpen(_stream)) {
CFReadStreamSetClient(_stream, 0, NULL, NULL);
CFReadStreamUnscheduleFromRunLoop(_stream, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);
CFRelease(_stream);
_stream = NULL;
return kStreamOpenFailed;
}
return kOK;
}



/* getRegData */ - (NSString*)getRegData { NSString *rawData = @"&serial="; rawData = [rawData stringByAppendingString:m_serial]; rawData = [rawData stringByAppendingString:@"&title="]; rawData = [rawData stringByAppendingString:[m_title stringValue]]; rawData = [rawData stringByAppendingString:@"&first="]; rawData = [rawData stringByAppendingString:[m_firstName stringValue]]; rawData = [rawData stringByAppendingString:@"&last="]; rawData = [rawData stringByAppendingString:[m_lastName stringValue]]; return rawData; }


On Nov 10, 2010, at 4:10 PM, Laurent Daudelin wrote:

Hello all.

I'm downloading a web page that contains a form with NSURLConnection. The form contains a few fields that I can fill with values.
Here is the form part:


<form id="loginform" action="/openid/loginsubmit" method="post" style="position:relative; style="position:relative;"">
<h2>Sign In</h2>
<div class="block-content">
<p>
<label for="first_name">First Name:</label>
<input type="text" size="25" name="first_name" id="first_name" value=""/>
</p>
<p>
<label for="last_name">Last Name:</label>
<input type="text" size="25" name="last_name" id="last_name" value=""/>
</p>
<!--
<p>
<input type="text" size="25" name="username" id="username" value=""/>
</p>
-->
<p>
<label for="password">Password:</label>
<input type="password" size="16" name="password" id="password"/>
</p>
<p class="resetpass"><a href="https://somewebsite.com/account/request.php?lang=en ">Forgot your login information?</a>
</p>
</div>
<div class="clearfix" style="padding-left:38%">
<button type="submit" name="Submit" class="css_button_hot btn_large primary">Login</button>
</div>
<input type="hidden" name="return_to" value="https:// somewebsite.com/"/>
<input type="hidden" name="previous_language" value="en_US"/>
<input type="hidden" name="language" value="en_US"/>
</form>


Now, how would I submit it back to the server?

Thanks in advance for any pointer, info or help!

-Laurent.
--
Laurent Daudelin
AIM/iChat/Skype:LaurentDaudelin 				http://www.nemesys-soft.com/
Logiciels Nemesys Software              			email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Submitting a web form? (From: Laurent Daudelin <email@hidden>)

  • Prev by Date: NSSecureTextFieldCell detected a field editor ((null))
  • Next by Date: Re: NSTableView within NSScrollView in code
  • Previous by thread: Re: Submitting a web form?
  • Next by thread: CALayer convertPoint:toLayer: affecting animations bug?
  • Index(es):
    • Date
    • Thread