Simple HTTP Post from iOS to Server created with ofxHTTP

Hello,

I’m trying to make a simple form post from iOS to a server created with @bakercp’s ofxHTTP. Right now, I’m just running the example basic post server from the ofxHTTP, since it already handles form post events.

When I post the data from iOS, I get a successful NSURLConnection to the server. However, OF does not seem to be receiving the data. Can anyone offer some help?

iOS Code

`

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://127.0.0.1/:7890/"]];
NSString *post = @"name=Jane+Doe&address=123+Main+St";
[request setHTTPMethod:@"POST"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:[NSData dataWithBytes:[post UTF8String] length:strlen([post UTF8String])]];

NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];

if(conn) {
    NSLog(@"Connection Successful");
} else {
    NSLog(@"Connection could not be made");
}`

Openframeworks Code
-I’m using the “example_basic_post_server” from ofxHTTP addon.

Thanks for any help!

Make sure you’re using the address of the post route, which is (by default) configured to be /post. You can change this in the settings.

So perhaps this modification:

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://127.0.0.1/:7890/post"]];

To change the settings, I believe you can do:

settings.postRouteSettings.setRoutePathPattern("/");

This will make the PostRoute respond to POST requests on the same route path as the file server (which only responds to GET requests by default.

Thanks @bakercp! This is exactly what I was looking for.

1 Like