0
NSURL *url = [NSURL URLWithString:@"appName://<?xml version=\"1.0\" encoding=\"UTF-8\"?>"];

But the url = nil. I found if I remove the "<" and ">" signs, it will be ok. So, the two signs cannot be used in a URL? Should I replace the signs with another one?

Thanks!

koregan
  • 10,054
  • 4
  • 23
  • 36
EVA
  • 375
  • 1
  • 6
  • 18

3 Answers3

2

I solved this problem. Before I do NSURL *url = [NSURL URLWithString:@"...."]; I first do:

    NSString *urlStr = [string stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

And when parse this url on the receiver side, I firstly do:

NSString *urlString = [[url absoluteString] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; // url is a NSURL
EVA
  • 375
  • 1
  • 6
  • 18
1

Why would you not just POST the document in the body of the request?

GET requests are not designed for this. You may get into difficulty if there are UTF-8 chars in the document.

Also What is the maximum length of a URL in different browsers? implies a max of 2083 chars.

You're into a very browser/proxy dependent scenario.

Community
  • 1
  • 1
koregan
  • 10,054
  • 4
  • 23
  • 36
  • 1
    Well, I'm not using in a http protocal, I just want to call my app from another app by openurl. And pass it some complicated params, which I think xml is better. So, how can I pass this xml via a url? – EVA Feb 23 '12 at 02:05
  • sorry, I missed that part. Your escaping suggestion should work and I haven't heard of any limits on the url length. Would the clipboard also be an option for larger data structure? – koregan Feb 23 '12 at 07:53
0

Theoretically yes. You can use urlEncode to do this. The HTTP protocol does not place any limit on the length of the URL.

RFC says:

Note: Servers ought to be cautious about depending on URI lengths above 255 bytes, because some older client or proxy implementations might not properly support these lengths.

AJ.
  • 2,561
  • 9
  • 46
  • 81