Reputation: 2741
NSString *message = [[NSString alloc] initWithFormat:@"<?xml version=\"1.0\" ?>\n<url><loc>http://www.abc.co.uk/index.php</loc><lastmod>2014-02-08</lastmod><changefreq>Monthly</changefreq><priority>0.9</priority></url>"];
NSString *url = [NSURL URLWithString:@"http://www.mypath.co.uk/ifo.xml"];
NSMutableURLRequest *Request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];
[Request setHTTPMethod:@"POST"];
[Request setValue:@"application/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[Request setHTTPBody:[message dataUsingEncoding:NSUTF8StringEncoding]];
NSError *Error = nil;
NSLog(@"%@Post message", message);
Status.text = message;
_Connection = [[NSURLConnection alloc] initWithRequest:Request delegate:self];
if(_Connection)
{
NSLog(@"Connection Build");
}
else
{
NSLog(@"Connection error...");
NSLog(@"%@",Error);
}
Anyone who use this please figure out the problem here.
On button click the request method is called.
Thanks in advance.
NSLog
: shows the error
NSURL length]: unrecognized selector sent to instance 0x89dac30
2014-02-14 15:55:26.513 eAgent[2369:a0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURL length]: unrecognized selector sent to instance 0x89dac30'
Upvotes: 1
Views: 347
Reputation: 5654
The problem is:
NSString *url = [NSURL URLWithString:@"http://www.mypath.co.uk/ifo.xml"];
NSMutableURLRequest *Request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];
URLWithString
is a NSURL
class method and it returns an NSURL
not an NSString
. Change that and in the request use the resultant NSURL
object and the errors will go away.
Like so:
NSURL *url = [NSURL URLWithString:@"http://www.mypath.co.uk/ifo.xml"];
NSMutableURLRequest *Request = [NSMutableURLRequest requestWithURL:url];
Upvotes: 1