Questions and solutions for passing parameters through 24-URL in iOS learning notes

Source: Internet
Author: User

 


1. When using JSON to parse the service on the server side, a request URL must be provided. This URL sometimes needs to pass some parameters. If these parameters are English or numbers, the request will fail.


[Plain]
NSString * urlString = @ "http: // ·. aspx? N = James ";
UrlString = [urlString stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
NSURL * url = [NSURL urlWithString: urlString];

2. another common problem is the special character issue.
The following are some special characters of ASII (hexadecimal encoding)

+ Space % 2B in URL
The space in the space URL can be + or encoded as % 20
/Separate directories and subdirectories % 2F
? Separate the actual URL and parameter % 3F
% Special characters % 25
# Indicates bookmarks % 23
& Delimiter between parameters specified in the URL % 26
= The value of the specified parameter in the URL % 3D

Take space as an Example

 

NSString * urlString = @ "http: // ·. aspx? T = 20:00:30 ";
UrlString = [urlString replaceOccurrencesOfString: @ "" withString: @ "% 20"];


In this way, the Service will receive spaces correctly when it is accepted.

 


 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.