Error[8]: Undefined offset: 4, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述这是我如何将查询参数添加到基本URL: let baseURL: URL = ...let queryParams: [AnyHashable: Any] = ...var components = URLComponents(url: baseURL, resolvingAgainstBaseURL: false)components?.queryItems = queryParams.m 这是我如何将查询参数添加到基本URL:
let baseURL: URL = ...let queryParams: [AnyHashable: Any] = ...var components = URLComponents(url: baseURL,resolvingAgainstBaseURL: false)components?.queryItems = queryParams.map { URLqueryItem(name: query​Items,value: "\()") }let finalURL = components?.url

当其中一个值包含符号时​​,就会出现问题.由于某种原因,它在最终的URL中没有编码为+,而是保留.如果我自己编码并传递+,则NSURL编码%,’plus’变为%2B.

问题是我如何在NSURL的实例中拥有+?

附:我知道,如果我自己构造一个查询字符串,然后简单地将结果传递给NSURL的构造函数init?(字符串:),我甚至不会遇到这个问题.

解决方法 正如在其他答案中指出的那样,“”字符在
一个查询字符串,这也在
let queryParams = ["foo":"a+b","bar": "a-b","baz": "a b"]var components = URLComponents()var cs = CharacterSet.urlqueryAllowedcs.remove("+")components.scheme = "http"components.host = "www.example.com"components.path = "/somepath"components.percentEncodedquery = queryParams.map {    
let queryParams = ["foo":"a+b","baz": "a b"]var components = URLComponents()components.scheme = "http"components.host = "www.example.com"components.path = "/somepath"components.queryItems = queryParams.map { URLqueryItem(name: [+++],value: ) }components.percentEncodedquery = components.percentEncodedquery?    .replacingOccurrences(of: "+",with: "%2B")let finalURL = components.urlprint(finalURL!)// http://www.example.com/somepath?bar=a-b&baz=a%20b&foo=a%2Bb
.addingPercentEnCoding(withAllowedCharacters: cs)! + "=" + .addingPercentEnCoding(withAllowedCharacters: cs)!}.joined(separator: "&")let finalURL = components.url// http://www.example.com/somepath?bar=a-b&baz=a%20b&foo=a%2Bb
文档.

另一方面,
W3C recommendations for URI addressing
说明

Within the query string,the plus sign is reserved as shorthand notation for a space. Therefore,real plus signs must be encoded. This method was used to make query URIs easIEr to pass in systems which dID not allow spaces.

这可以通过“手动”构建来实现
百分比编码的查询字符串,使用自定义字符集:

[+++]

另一种选择是对生成的加号进行“后编码”
百分比编码的查询字符串:

[+++] 总结

以上是内存溢出为你收集整理的ios – 在Swift中使用URLComponents编码”全部内容,希望文章能够帮你解决ios – 在Swift中使用URLComponents编码”所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 5, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述这是我如何将查询参数添加到基本URL: let baseURL: URL = ...let queryParams: [AnyHashable: Any] = ...var components = URLComponents(url: baseURL, resolvingAgainstBaseURL: false)components?.queryItems = queryParams.m 这是我如何将查询参数添加到基本URL:
let baseURL: URL = ...let queryParams: [AnyHashable: Any] = ...var components = URLComponents(url: baseURL,resolvingAgainstBaseURL: false)components?.queryItems = queryParams.map { URLqueryItem(name: query​Items,value: "\()") }let finalURL = components?.url

当其中一个值包含符号时​​,就会出现问题.由于某种原因,它在最终的URL中没有编码为+,而是保留.如果我自己编码并传递+,则NSURL编码%,’plus’变为%2B.

问题是我如何在NSURL的实例中拥有+?

附:我知道,如果我自己构造一个查询字符串,然后简单地将结果传递给NSURL的构造函数init?(字符串:),我甚至不会遇到这个问题.

解决方法 正如在其他答案中指出的那样,“”字符在
一个查询字符串,这也在
let queryParams = ["foo":"a+b","bar": "a-b","baz": "a b"]var components = URLComponents()var cs = CharacterSet.urlqueryAllowedcs.remove("+")components.scheme = "http"components.host = "www.example.com"components.path = "/somepath"components.percentEncodedquery = queryParams.map {    
let queryParams = ["foo":"a+b","baz": "a b"]var components = URLComponents()components.scheme = "http"components.host = "www.example.com"components.path = "/somepath"components.queryItems = queryParams.map { URLqueryItem(name: ,value: ) }components.percentEncodedquery = components.percentEncodedquery?    .replacingOccurrences(of: "+",with: "%2B")let finalURL = components.urlprint(finalURL!)// http://www.example.com/somepath?bar=a-b&baz=a%20b&foo=a%2Bb
.addingPercentEnCoding(withAllowedCharacters: cs)! + "=" + .addingPercentEnCoding(withAllowedCharacters: cs)!}.joined(separator: "&")let finalURL = components.url// http://www.example.com/somepath?bar=a-b&baz=a%20b&foo=a%2Bb
文档.

另一方面,
W3C recommendations for URI addressing
说明

Within the query string,the plus sign is reserved as shorthand notation for a space. Therefore,real plus signs must be encoded. This method was used to make query URIs easIEr to pass in systems which dID not allow spaces.

这可以通过“手动”构建来实现
百分比编码的查询字符串,使用自定义字符集:

[+++]

另一种选择是对生成的加号进行“后编码”
百分比编码的查询字符串:

[+++] 总结

以上是内存溢出为你收集整理的ios – 在Swift中使用URLComponents编码”全部内容,希望文章能够帮你解决ios – 在Swift中使用URLComponents编码”所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 6, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述这是我如何将查询参数添加到基本URL: let baseURL: URL = ...let queryParams: [AnyHashable: Any] = ...var components = URLComponents(url: baseURL, resolvingAgainstBaseURL: false)components?.queryItems = queryParams.m 这是我如何将查询参数添加到基本URL:
let baseURL: URL = ...let queryParams: [AnyHashable: Any] = ...var components = URLComponents(url: baseURL,resolvingAgainstBaseURL: false)components?.queryItems = queryParams.map { URLqueryItem(name: query​Items,value: "\()") }let finalURL = components?.url

当其中一个值包含符号时​​,就会出现问题.由于某种原因,它在最终的URL中没有编码为+,而是保留.如果我自己编码并传递+,则NSURL编码%,’plus’变为%2B.

问题是我如何在NSURL的实例中拥有+?

附:我知道,如果我自己构造一个查询字符串,然后简单地将结果传递给NSURL的构造函数init?(字符串:),我甚至不会遇到这个问题.

解决方法 正如在其他答案中指出的那样,“”字符在
一个查询字符串,这也在
let queryParams = ["foo":"a+b","bar": "a-b","baz": "a b"]var components = URLComponents()var cs = CharacterSet.urlqueryAllowedcs.remove("+")components.scheme = "http"components.host = "www.example.com"components.path = "/somepath"components.percentEncodedquery = queryParams.map {    
let queryParams = ["foo":"a+b","baz": "a b"]var components = URLComponents()components.scheme = "http"components.host = "www.example.com"components.path = "/somepath"components.queryItems = queryParams.map { URLqueryItem(name: ,value: ) }components.percentEncodedquery = components.percentEncodedquery?    .replacingOccurrences(of: "+",with: "%2B")let finalURL = components.urlprint(finalURL!)// http://www.example.com/somepath?bar=a-b&baz=a%20b&foo=a%2Bb
.addingPercentEnCoding(withAllowedCharacters: cs)! + "=" + .addingPercentEnCoding(withAllowedCharacters: cs)!}.joined(separator: "&")let finalURL = components.url// http://www.example.com/somepath?bar=a-b&baz=a%20b&foo=a%2Bb
文档.

另一方面,
W3C recommendations for URI addressing
说明

Within the query string,the plus sign is reserved as shorthand notation for a space. Therefore,real plus signs must be encoded. This method was used to make query URIs easIEr to pass in systems which dID not allow spaces.

这可以通过“手动”构建来实现
百分比编码的查询字符串,使用自定义字符集:

另一种选择是对生成的加号进行“后编码”
百分比编码的查询字符串:

[+++] 总结

以上是内存溢出为你收集整理的ios – 在Swift中使用URLComponents编码”全部内容,希望文章能够帮你解决ios – 在Swift中使用URLComponents编码”所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
ios – 在Swift中使用URLComponents编码”_app_内存溢出

ios – 在Swift中使用URLComponents编码”

ios – 在Swift中使用URLComponents编码”,第1张

概述这是我如何将查询参数添加到基本URL: let baseURL: URL = ...let queryParams: [AnyHashable: Any] = ...var components = URLComponents(url: baseURL, resolvingAgainstBaseURL: false)components?.queryItems = queryParams.m 这是我如何将查询参数添加到基本URL:
let baseURL: URL = ...let queryParams: [AnyHashable: Any] = ...var components = URLComponents(url: baseURL,resolvingAgainstBaseURL: false)components?.queryItems = queryParams.map { URLqueryItem(name: query​Items,value: "\()") }let finalURL = components?.url

当其中一个值包含符号时​​,就会出现问题.由于某种原因,它在最终的URL中没有编码为+,而是保留.如果我自己编码并传递+,则NSURL编码%,’plus’变为%2B.

问题是我如何在NSURL的实例中拥有+?

附:我知道,如果我自己构造一个查询字符串,然后简单地将结果传递给NSURL的构造函数init?(字符串:),我甚至不会遇到这个问题.

解决方法 正如在其他答案中指出的那样,“”字符在
一个查询字符串,这也在
let queryParams = ["foo":"a+b","bar": "a-b","baz": "a b"]var components = URLComponents()var cs = CharacterSet.urlqueryAllowedcs.remove("+")components.scheme = "http"components.host = "www.example.com"components.path = "/somepath"components.percentEncodedquery = queryParams.map {    
let queryParams = ["foo":"a+b","baz": "a b"]var components = URLComponents()components.scheme = "http"components.host = "www.example.com"components.path = "/somepath"components.queryItems = queryParams.map { URLqueryItem(name: ,value: ) }components.percentEncodedquery = components.percentEncodedquery?    .replacingOccurrences(of: "+",with: "%2B")let finalURL = components.urlprint(finalURL!)// http://www.example.com/somepath?bar=a-b&baz=a%20b&foo=a%2Bb
.addingPercentEnCoding(withAllowedCharacters: cs)! + "=" + .addingPercentEnCoding(withAllowedCharacters: cs)!}.joined(separator: "&")let finalURL = components.url// http://www.example.com/somepath?bar=a-b&baz=a%20b&foo=a%2Bb
文档.

另一方面,
W3C recommendations for URI addressing
说明

Within the query string,the plus sign is reserved as shorthand notation for a space. Therefore,real plus signs must be encoded. This method was used to make query URIs easIEr to pass in systems which dID not allow spaces.

这可以通过“手动”构建来实现
百分比编码的查询字符串,使用自定义字符集:

另一种选择是对生成的加号进行“后编码”
百分比编码的查询字符串:

总结

以上是内存溢出为你收集整理的ios – 在Swift中使用URLComponents编码”全部内容,希望文章能够帮你解决ios – 在Swift中使用URLComponents编码”所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1100377.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存