I'm trying to understand how to send an image with http POST and my current client-server protocol design.
All the messages from client to server looks like the example below, there is a cmd string with parameter cmd
and some more relevant parameters for the command.
For example this is how i send a text message to the server:
- (void)sendMessagesWithText:(NSString *)text fromUser:(NSString *)userId
{
NSString *url = SERVER_URL;
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:url]];
[request setHTTPMethod:@"POST"];
NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@"cmd=%@&userid=%@&msgtext=%@",
@"sendmessage",
userId,
text] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];
// send to server
[[NetworkHelper sharedManager] sendRequest:request];
}
Now I want to enable the user to send also an image, but how do I send it with my protocol design? should i just append the image to the body after the cmd string?