• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Sending a non http request
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Sending a non http request
      • From: Mike Abdullah <email@hidden>
    • Re: Sending a non http request
      • From: Andrew Farmer <email@hidden>
  • Prev by Date: Re: [iPhone] Sample code for live camera stream?
  • Next by Date: Re: [iPhone] Sample code for live camera stream?
  • Previous by thread: Re: Setting the port of an NSURL
  • Next by thread: Re: Sending a non http request
  • Index(es):
    • Date
    • Thread