查看Android源代码:
https://android.googlesource.com/platform/frameworks/base/+/master/wifi/java/android/net/wifi/hotspot2/ConfigParser.java
原来你需要用Base64对所有内容进行双重编码。
最后我编写了一个小的python实用程序来实现这一点。
注意:为了让android接受这个配置文件,您需要使用https来提供这个服务。另外,你需要使用chrome浏览器。stock/firefox不能在我的手机上使用
@app.route('/profiles/<filename>')
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