Post data to aspx page from iphone application

Posted by Dipen on Stack Overflow See other posts from Stack Overflow or by Dipen
Published on 2010-05-01T07:57:04Z Indexed on 2010/05/01 8:07 UTC
Read the original article Hit count: 598

Filed under:
|
|
Hi,



I am developing a application. In which i am posting a image to .aspx page.The HTML for the page is as below.



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>">



<html xmlns="http://www.w3.org/1999/xhtml>">

<head><title>

Untitled Page

</title><link href="App_Themes/XXX/XXX.css" type="text/css" rel="stylesheet" /></head>

<body>

    <form name="form1" method="post" action="Default16.aspx" id="form1" enctype="multipart/form-data">

<div>

<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKLTQwMjY2MDA0Mw9kFgICAw8WAh4HZW5jdHlwZQUTbXVsdGlwYXJ0L2Zvcm0tZGF0YWRktr+hG1VVXZsO01PCyj61d6Ulqy8=" />

</div>



    <div>

        <div style="float:left;margin:10px">

            <input type="file" name="fuImage" id="fuImage" />

        </div>

        <div style="float:right">

            <input type="submit" name="btnPost" value="Post Image" id="btnPost" />

        </div>

    </div>

    </form>

</body>

</html>





Now i am sending a request from my application then i am getting " Error Domain=kCFErrorDomainCFNetwork Code=303 UserInfo=0xf541c0 "Operation could not be completed. (kCFErrorDomainCFNetwork error 303.)""



I have tried using SynchronousRequest and aSynchronousRequest but both are not working. I have also used apple sample code.



Here is the code for iPhone app



UIImage *image=[UIImage imageNamed:@"photo2.jpg"];



NSData *imageData = UIImageJPEGRepresentation(image, 90);






NSString *urlString = @"http://XXXXXXXX.com/Post.aspx";



NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];

[request setURL:[NSURL URLWithString:urlString]];

[request setHTTPMethod:@"POST"];



NSString *boundary = [NSString stringWithString:@"----WebKitFormBoundarylU9pAl5wPrF+Tk52"];

NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];

[request addValue:contentType forHTTPHeaderField:@"Content-Type"];



NSMutableData *body = [NSMutableData data];

[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];

[body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"fuimage\"; filename=\"asd.jpg\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];

[body appendData:[[NSString stringWithString:@"Content-Type: image/jpeg\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];

[body appendData:[NSData dataWithData:imageData]];

[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];

[request setHTTPBody:body];



// NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];

// NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];



// NSLog(returnString);


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


if( theConnection )

{

webData = [[NSMutableData data] retain];

}

else

{

NSLog(@"theConnection is NULL");

}





Thanks in Advance.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about post