事实证明,您需要对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