Sending a non http request
Sending a non http request
- Subject: Sending a non http request
- From: Development <email@hidden>
- Date: Tue, 15 Dec 2009 15:22:54 -0700
I am trying to post data to NSString * url = [NSString stringWithFormat:@"ipp://%@:%i/%@",host,[service port],item];
Which as you can see is an ipp address. However the code below fails as I get an error from the NSError that I am using an unsupported url. Obviously if I send it as http:// all I get is the cups page. So the question then is how to format this url or how to send the request.
NSMutableData * sendData= [[NSMutableData alloc]init];
NSMutableData * body= [[NSMutableData alloc]init];
NSString * boundry = @"@@##$$rew**&&^%^";
NSInputStream* stream = [[[NSInputStream alloc]initWithData:imageData] retain];
[body appendData:[[NSString stringWithFormat:@"--%@\r\n",boundry]dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Type: image/png\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:imageData];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundry]dataUsingEncoding:NSUTF8StringEncoding]];
//int totalSize =[body length];
[sendData appendData:body];
NSMutableURLRequest* post = [NSMutableURLRequest requestWithURL: [NSURL URLWithString:path]];
[post addValue: @"application/ipp; boundary=@@##$$rew**&&^%^" forHTTPHeaderField: @"Content-Type"];
[post setHTTPBodyStream:stream];
[post setHTTPMethod: @"POST"];
[post setHTTPBody:sendData];
NSURLResponse* response;
NSError* error;
NSLog(@"Sending request now %@",[NSURL URLWithString:path]);
NSLog(@"Scheme: %@",[[NSURL URLWithString:path]scheme]);
NSLog(@"Port %@",[[NSURL URLWithString:path]port]);
NSData* result = [NSURLConnection sendSynchronousRequest:post returningResponse:&response error:&error];
NSString * incoming = [[[NSString alloc] initWithData:result encoding:NSASCIIStringEncoding] autorelease];
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden