Thank you. After few more googles, I got it done. Here is the snippet
for reference
NSURL *cgiUrl = [NSURL URLWithString:@"
http://myserver.com"];
NSMutableURLRequest *postRequest = [NSMutableURLRequest
requestWithURL:cgiUrl];
//adding header information:
[postRequest setHTTPMethod:@"POST"];
NSString *stringBoundary = [NSString
stringWithString:@"0xKhTmLbOuNdArY"];
NSString *contentType = [NSString stringWithFormat:@"multipart/form-
data; boundary=%@",stringBoundary];
[postRequest addValue:contentType forHTTPHeaderField: @"Content-
Type"];
//setting up the body:
NSMutableData *postBody = [NSMutableData data];
[postBody appendData:[[NSString stringWithFormat:@"--%@\r
\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:@"Content-
Disposition: form-data; name=\"uploadFile\"; filename=\"%@\"\r
\n",filename] dataUsingEncoding:NSUTF8StringEncoding]];
//[postBody appendData:[[NSString stringWithString:@"Content-Type:
application/octet-stream\r\n\r\n"]
dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[@"Content-Type: image/jpeg\r\n\r\n"
dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:imageData];
[postBody appendData:[[NSString stringWithFormat:@"\r\n--%@--\r
\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postRequest setHTTPBody:postBody];
NSHTTPURLResponse *theResponse = nil;
NSError *theError = nil;
NSString* ret =nil;
NSData *theResponseData = [NSURLConnection
sendSynchronousRequest:postRequest returningResponse:&theResponse
error:&theError];
if (theResponseData == nil || [theResponse statusCode]!=200)
{
return nil;
} else
{
ret = [[NSString alloc] initWithData:theResponseData
encoding:NSUTF8StringEncoding];
}
On Apr 12, 10:56 am, "Steve Shi" <
stevesh...@gmail.com> wrote:
> Hi David,
>
> Thanks for your pointer. but... I would like to know:
> Is that a conceptual idea that you have in mind which you believe will work
> this way or have you already implemented this code successfully and it works
> without a hitch?
>
> Steve
>
> On Fri, Apr 11, 2008 at 3:57 AM, David Phillip Oster <
>