Git Product home page Git Product logo

Comments (5)

goodryb avatar goodryb commented on July 18, 2024 1

@Finb 好的,测试了下应该没问题了

做了一个alfred文本推送 BarkSendMessage

from bark.

Finb avatar Finb commented on July 18, 2024

只需要URL编码即可
举一个复杂的例子
把一个带特殊字符的URL当成另外一个URL的参数

  1. 首先确保参数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"
  1. 将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.

goodryb avatar goodryb commented on July 18, 2024

sorry ,可能是我提问给的信息不对,说下我遇到的一个需求,比如说我有个文件,里面有几行(示例)内容

测试001
测试002
测试003

我想把这个内容通过bark发送到我手机上,现在似乎一次操作是无法完成的,因为这个是多行文本

from bark.

Finb avatar Finb commented on July 18, 2024

@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.

Finb avatar Finb commented on July 18, 2024

@goodryb
通常,你不需要关心内容是否需要编码,只需要对你要发送的内容,都调用一次URL编码方法即可
let str = {无论从哪读的数据,不管何种格式何种内容}.encodeURIComponent()
再把str 拼接到 pushUrl 即可

from bark.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.