android http常用配置文件,编码多部分/混合HTTP响应(适用于Android配置文件)

事实证明,您需要对base64中的所有内容进行双重编码。

我最终写了一个小的python实用程序来解决这个问题。

注意:您需要将此服务与HTTPS配合使用,以便Android接受配置文件。另外,您需要使用Chrome浏览器。 Stock / Firefox无法在我的手机上与此配合使用

@app.route('/profiles/')

def multipart(filename):

if("/" in filename):

raise "ilegal name: "+filename

with open(filename, 'r') as myfile:

profileData = myfile.read()

#print data

b64Profile=b64encode(profileData).decode('ascii')

with open("cert.crt", 'r') as myfile:

caCertData = myfile.read()

#print data

b64CaCert=b64encode(caCertData).decode('ascii')

withHeaders='''Content-Type: multipart/mixed; boundary=f6d6201be73d4e46988f789237cffb00

Content-Transfer-Encoding: base64

--f6d6201be73d4e46988f789237cffb00

Content-Type: application/x-passpoint-profile

Content-Transfer-Encoding: base64

'''+ b64Profile+'''

--f6d6201be73d4e46988f789237cffb00

Content-Type: application/x-x509-ca-cert

Content-Transfer-Encoding: base64

'''+b64CaCert+'''

--f6d6201be73d4e46988f789237cffb00--'''

b64withHeaders=b64encode(withHeaders).decode('ascii')

resp = make_response(b64withHeaders) #here you could use make_response(render_template(...)) too

resp.headers['Content-Type'] = 'application/x-wifi-config'

resp.headers['Content-Transfer-Encoding'] = 'base64'

#resp.headers['Content-Type'] = 'multipart/mixed; boundary=f6d6201be73d4e46988f789237cffb00'

return resp

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值