4

This is appears only on iOS 8. For earlier versions, it is fine.

Examples:

For iOS 7.1:

NSString *url = @"http://www.example.com/api/search?name=test&page=1";
NSMutableURLRequest *urlRequest = [[NSMutableURLRequest alloc] init];
[urlRequest setURL:[NSURL URLWithString:url]];

Getting urlRequest as

<NSMutableURLRequest: 0x7b787130> { URL: http://www.example.com/api/search?name=test&page=1 }

For iOS 8.0:

NSString *url = @"http://www.example.com/api/search?name=test&page=1";
NSMutableURLRequest *urlRequest = [[NSMutableURLRequest alloc] init];
[urlRequest setURL:[NSURL URLWithString:url]];

Getting urlRequest as

<NSMutableURLRequest: 0x7b6246d0> { URL: http://www.example.com/api/search?name=test&page=1, headers: (null) }

Error for iOS 8.0: Error 400 (Bad Request)

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62

1 Answers1

0

You are misunderstanding that log. It just means that

URL = "http://www.example.com/api/search?name=test&page=1"

and

headers = null

What you should be debugging are the actual headers:

NSLog("%@", urlRequest.allHTTPHeaderFields);
John Estropia
  • 17,460
  • 4
  • 46
  • 50
  • Maybe, however shouldn't the OP be setting at least one header (i.e. `Content-Type`) so the server knows what it's getting? – trojanfoe Sep 22 '14 at 10:31
  • @trojanfoe and John Estropia actually we are calling google map api when we are using "[urlRequest setURL:[NSURL URLWithString:url]];" and print a nslog then getting url like "https://maps.googleapis.com/maps/api/place/search/json?key=yourkey&location=lat,long&radius=radius,%20headers:%20(null)" – Ashutosh Srivastava Sep 22 '14 at 10:41
  • @AshutoshSrivastava Why are you drip-feeding details to us? How about full disclosure right from the start? – trojanfoe Sep 22 '14 at 10:42