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)
- 连接了电信wifi,服务器错误了,用5g服务器可以用了,哪里有什么问题 HOT 2
- 能否添加自定义的铃声通知 HOT 2
- 有没有反向推送的操作 HOT 1
- Utools插件推荐
- Safari Extension下载
- 可否不推送空白的内容到app HOT 1
- 是否可以支持重要警告消息? HOT 1
- Minor English Correction
- 如何设置像来电一样的提醒?除非主动按掉,否则一直响铃 HOT 3
- Python script for msg sender with AES-256-CBC
- Suggestion to Optimize AES Key Encoding Method
- 请问有安卓端的替代品吗?
- bark闪退
- bark能否实现定时推送的功能 HOT 1
- 作者您好,想咨询一下icon能否刷新. HOT 1
- 可以支持自动粘贴吗 HOT 2
- iv 中包含 \r\n 导致 Decryption Failed
- 一个功能更完善的Python包,支持所有参数
- 在IOS17.2.1上使用,通知无法亮屏 HOT 2
- 电报群邀请链接过期了 HOT 1
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.