views:

180

answers:

1

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&gt;"&gt;
<html xmlns="http://www.w3.org/1999/xhtml&gt;"&gt;
<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");
}
+1  A: 

As a general rule, if you want to post data from an external source (other than aspx, which does some crazy stuff) you are much better with a simple "handler" (ashx) or an ASP.NET MVC route. In the "handler" case you can access the request form/query-string etc directly. In the MVC case it should mostly be done for you.

aspx is not a friend to raw posts.

In the specific case, kCFErrorDomainCFNetwork suggests some kind of network error, but you would need a http trace to identify it for sure.

Marc Gravell
Thanks for reply. I have tried with other ways now i am not getting any error but also am not able to get any response from server side. Also when i am sending request to the server from iPhone application server can not able to get request from the app. Do you have idea for this issue? Is there any issue with iPhone architecture? Please give me your suggestion. I will go on the direction given by you.Thanks.
Dipen