I'm looking to create a cocoa program that simply sends data typed into text fields to an HTTP form.
I have all of the various connection details worked out, I just can't seem to get the posted string to target the text fields. This is what I have for the form:
<html>
<body>
<form action='test.php' method='post'>
Name: <input type='text' name='nameOfPerson'/>
Age: <input type='text' name='ageOfPerson'/>
<input type='submit'/>
</form>
</body>
</html>
and for the cocoa...
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]
initWithURL:[NSURL URLWithString:@"http://localhost:8888/CocoaFormPractice/form.html"]];
[request setHTTPMethod:@"POST"];
[request setValue:@"text/html" forHTTPHeaderField:@"Content-type"];
NSString *xmlString = @"nameOfPerson:test&ageOfPerson:123";
[request setValue:[NSString stringWithFormat:@"%d", [xmlString length]] forHTTPHeaderField:@"Content-length"];
[request setHTTPBody:[xmlString dataUsingEncoding:NSUTF8StringEncoding]];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
[request release];
I know that the value I'm using in the xmlString is bogus, and not even XML.