Comments (5)
@Finb 好的,测试了下应该没问题了
做了一个alfred文本推送 BarkSendMessage
from bark.
只需要URL编码即可
举一个复杂的例子
把一个带特殊字符的URL当成另外一个URL的参数
- 首先确保参数URL合法(将URL路径或参数中的特殊字符或中文 URL 编码)
//参数URL:
let wd = "特殊字符/&%^".encodeURIComponent()
print(wd) //"%E7%89%B9%E6%AE%8A%E5%AD%97%E7%AC%A6%2F%26%25%5E"
let url1 = "https://www.baidu.com/s?wd=\(wd)"
print(url1) //"https://www.baidu.com/s?wd=%E7%89%B9%E6%AE%8A%E5%AD%97%E7%AC%A6%2F%26%25%5E"
- 将url1 当成另外一个URL的参数,因为url1 里面有特殊字符,所以需要对url1编码, (通常应该对所有参数进行编码,编码方法会对需要编码的字符编码,不需要的保持原样)
let encodeUrl = url1.encodeURIComponent()
print(encodeUrl) //"https%3A%2F%2Fwww.baidu.com%2Fs%3Fwd%3D%25E7%2589%25B9%25E6%25AE%258A%25E5%25AD%2597%25E7%25AC%25A6%252F%2526%2525%255E"
let pushUrl = "https://api.day.app/yourkey/test?url=\(encodeUrl)"
print(pushUrl) //"https://api.day.app/yourkey/test?url=https%3A%2F%2Fwww.baidu.com%2Fs%3Fwd%3D%25E7%2589%25B9%25E6%25AE%258A%25E5%25AD%2597%25E7%25AC%25A6%252F%2526%2525%255E"
总结一下就是只需要对URL的参数或路径部分 ,都调用编码方法,确保URL合法 即可
from bark.
sorry ,可能是我提问给的信息不对,说下我遇到的一个需求,比如说我有个文件,里面有几行(示例)内容
测试001
测试002
测试003
我想把这个内容通过bark发送到我手机上,现在似乎一次操作是无法完成的,因为这个是多行文本
from bark.
@goodryb
换行符也算特殊符号,只需要URL编码即可,显示在客户端的就是换行的效果了
你的例子
let str = "测试001\n测试002\n测试003".encodeURIComponent()
print(str) //"测试001%0a测试002%0a测试003"
let pushUrl = "https://api.day.app/yourkey/测试001%0a测试002%0a测试003"
from bark.
@goodryb
通常,你不需要关心内容是否需要编码,只需要对你要发送的内容,都调用一次URL编码方法即可
let str = {无论从哪读的数据,不管何种格式何种内容}.encodeURIComponent()
再把str 拼接到 pushUrl 即可
from bark.
Related Issues (20)
- 作者您好,想咨询一下icon能否刷新. HOT 1
- 可以支持自动粘贴吗 HOT 2
- iv 中包含 \r\n 导致 Decryption Failed
- 一个功能更完善的Python包,支持所有参数
- 在IOS17.2.1上使用,通知无法亮屏 HOT 2
- 电报群邀请链接过期了 HOT 1
- 请问是否可以添加支持url scheme添加服务器
- iOS 17.3.1 cannot get device token
- 重置失败,没有获取到 DeviceToken HOT 1
- POST 请求参数问题 HOT 2
- ios增加自定义铃声设置 HOT 2
- 建议,能否增加定期自动清理
- 历史消息高亮未读消息
- device token变成了未知 HOT 1
- iOS 17.5.1 Decryption Failed HOT 4
- 消息图标不支持webp格式的吗?
- 有没有mac版本
- 自定义推送图标无效,请问是怎么回事 HOT 1
- 不支持静音按键 HOT 2
- 如何让加密设置的Iv(初始化向量)可以即时变化? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bark.