我正在开发一款应用。我想将图像发送到服务器,但我的解析没有调用,也没有得到任何响应。我尝试下面的代码。
-(void)callParsing
{
NSData *imgData=UIImageJPEGRepresentation(cameraImageView.image,0.5);
NSLog(@"%@",imgData);
NSString *regestrationString=[[NSString alloc]initWithFormat:@"http://humsomething.netsmartz.us/HumServices.svc/updateimage/vchImage=%@",imgData];
NSURLRequest *regestrationRequest=[[NSURLRequest alloc]initWithURL:[NSURL URLWithString:regestrationString]];
NSURLResponse *regestrationResponce;
NSError *error;
NSMutableData *regestrationData=[[NSMutableData alloc]initWithData:[NSURLConnection sendSynchronousRequest:regestrationRequest returningResponse:®estrationResponce error:&error]];
//[self performXML:regestrationData];
results = [[NSMutableArray alloc] init];
xmlParser = [[NSXMLParser alloc] initWithData:regestrationData];
[xmlParser setDelegate: self];
[xmlParser setShouldResolveExternalEntities: YES];
if([xmlParser parse])
{
NSLog(@"Sucessful");
}
else
{
NSLog(@"Failure");
}
}
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *) namespaceURI qualifiedName:(NSString *)qName
attributes: (NSDictionary *)attributeDict
{
if( [elementName isEqualToString:@"RegisterUserResult"] )
{
if(!soapResults)
{
soapResults = [[NSMutableString alloc] init];
}
[soapResults setString:@""];
recordResults = TRUE;
}
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if( recordResults )
{
[soapResults appendString:string];
NSLog(@"%@",soapResults);
}
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if([elementName isEqualToString:@"RegisterUserResult"])
{
[results addObject:soapResults];
NSLog(@" REPONSE %@",results);
}
答案 0 :(得分:0)
我正在使用以下作为我的数据的上传器。
-(void) Uploader:(NSData *) imageData fileName : (NSString *) Name
{
NSLog(@"%d",[imageData length]);
NSString *urlString = @".aspx URL";
// setting up the request object now
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];
/*
add some header info now
we always need a boundary when we post a file
also we need to set the content type
You might want to generate a random boundary.. this is just the same
as my output from wireshark on a valid html post
*/
NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"];
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
[request addValue:contentType forHTTPHeaderField: @"Content-Type"];
/*
now lets create the body of the post
*/
NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"userfile\"; filename=\"%@\"\r\n",Name] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:imageData]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
// setting the body of the post to the reqeust
[request setHTTPBody:body];
// now lets make the connection to the web
//NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
//NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
theConnection = [[[NSURLConnection alloc] initWithRequest:request delegate:self] autorelease];
if( theConnection )
{
webData = [[NSMutableData data] retain];
}
else
{
NSLog(@"theConnection is NULL");
}
uploadedData = 0.00;
totalData = [imageData length];
}