title: Post data to aspx page from iphone application
body: <p>I am developing a application. In which i am posting a image to .aspx page.The HTML for the page is as below.</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&gt;"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml&gt;"&gt;
  &lt;head&gt;&lt;title&gt;
  Untitled Page
  &lt;/title&gt;&lt;link href="App_Themes/XXX/XXX.css" type="text/css" rel="stylesheet" /&gt;&lt;/head&gt;
  &lt;body&gt;
      &lt;form name="form1" method="post" action="Default16.aspx" id="form1" enctype="multipart/form-data"&gt;    
  &lt;div&gt;    
  &lt;input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKLTQwMjY2MDA0Mw9kFgICAw8WAh4HZW5jdHlwZQUTbXVsdGlwYXJ0L2Zvcm0tZGF0YWRktr+hG1VVXZsO01PCyj61d6Ulqy8=" /&gt;
  &lt;/div&gt;
  &lt;div&gt;
       &lt;div style="float:left;margin:10px"&gt;
         &lt;input type="file" name="fuImage" id="fuImage" /&gt;
       &lt;/div&gt;
       &lt;div style="float:right"&gt;
              &lt;input type="submit" name="btnPost" value="Post Image" id="btnPost" /&gt;
       &lt;/div&gt;
     &lt;/div&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>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.)""</p>
  
  <p>I have tried using SynchronousRequest and aSynchronousRequest but both are not working. I have also used apple sample code.</p>
  
  <p>Here is the code for iPhone app</p>
  
  <pre><code>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");
  }
  </code></pre>