android和flask交互,java - 当我从Android向Flask Web服务发送参数时,如何解决“ SSL库故障”? - 堆栈内存溢出...

我确实尝试将一些值作为“ application / json ”从Android应用程序发送到Flask Web服务。 这是我的Java代码 :

Thread thread = new Thread(new Runnable() {

@Override

public void run() {

try {

URL url = new URL("https://192.168.43.31:5000/a/");

HttpURLConnection conn = (HttpURLConnection) url.openConnection();

conn.setRequestMethod("POST");

conn.setRequestProperty("Content-Type", "application/json;charset=UTF-8");

conn.setRequestProperty("Accept","application/json");

conn.setDoOutput(true);

conn.setDoInput(true);

JSONObject jsonParam = new JSONObject();

jsonParam.put("name", name);

Log.i("JSON", jsonParam.toString());

DataOutputStream os = new DataOutputStream(conn.getOutputStream());

//os.writeBytes(URLEncoder.encode(jsonParam.toString(), "UTF-8"));

os.writeBytes(jsonParam.toString());

os.flush();

os.close();

Log.i("STATUS", String.valueOf(conn.getResponseCode()));

Log.i("MSG" , conn.getResponseMessage());

conn.disconnect();

} catch (Exception e) {

e.printStackTrace();

}

}

});

thread.start();

python代码

#!flask/bin/python

from flask import Flask , request

app = Flask(__name__)

@app.route('/a/', methods=['GET', 'POST'])

def get_request1():

data = request.data

if __name__ == '__main__':

app.run(host="0.0.0.0",debug=True, port=5000)

但它显示此错误(烧瓶): aHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9lcFpCWS5wbmc=

所以我确实在android上跟踪了错误,发现了这个错误:

I/System.out: open:https://192.168.43.31:5000/a/

I/JSON: {"name":"gshzj"}

D/libc-netbsd: [getaddrinfo]: hostname=192.168.43.31; servname=(null); cache_mode=(null), netid=0; mark=0

[getaddrinfo]: ai_addrlen=0; ai_canonname=(null); ai_flags=4; ai_family=0

I/System.out: [CDS][DNS] getAllByNameImpl netId = 0

D/libc-netbsd: [getaddrinfo]: hostname=192.168.43.31; servname=(null); cache_mode=(null), netid=0; mark=0

[getaddrinfo]: ai_addrlen=0; ai_canonname=(null); ai_flags=4; ai_family=0

I/System: core_booster, getBoosterConfig = false

I/System.out: [CDS]rx timeout:0

I/System.out: [socket][0] connection /192.168.43.31:5000;LocalPort=34295(0)

[CDS]connect[/192.168.43.31:5000] tm:90

D/Posix: [Posix_connect Debug]Process com.sourcey.materialloginexample :5000

I/System.out: [socket][/192.168.43.1:34295] connected

I/System: core_booster, getBoosterConfig = false

D/libc-netbsd: [getaddrinfo]: hostname=192.168.43.31; servname=(null); cache_mode=(null), netid=0; mark=0

[getaddrinfo]: ai_addrlen=0; ai_canonname=(null); ai_flags=4; ai_family=0

D/Surface: Surface::setBuffersDimensions(this=0xb45af700,w=720,h=1184)

V/NativeCrypto: SSL handshake aborted: ssl=0xaf8326c8: Failure in SSL library, usually a protocol error

error:100000f7:SSL routines:OPENSSL_internal:WRONG_VERSION_NUMBER (third_party/openssl/boringssl/src/ssl/tls_record.cc:242 0x9b4bb9fe:0x00000000)

D/Surface: Surface::setBuffersDimensions(this=0xb45af700,w=720,h=1184)

I/System.out: [CDS]close[34295]

Close in OkHttp

I/System: core_booster, getBoosterConfig = false

I/System.out: [CDS]rx timeout:0

[socket][1] connection /192.168.43.31:5000;LocalPort=36619(0)

[CDS]connect[/192.168.43.31:5000] tm:90

D/Posix: [Posix_connect Debug]Process com.sourcey.materialloginexample :5000

I/System.out: [socket][/192.168.43.1:36619] connected

I/System: core_booster, getBoosterConfig = false

I/System.out: [CDS]close[36619]

W/System.err: javax.net.ssl.SSLHandshakeException: No enabled protocols; SSLv3 is no longer supported and was filtered from the list

W/System.err: at com.google.android.gms.org.conscrypt.NativeSsl.initialize(:com.google.android.gms@12673008@12.6.73 (020306-194189626):7)

at com.google.android.gms.org.conscrypt.ConscryptFileDescriptorSocket.startHandshake(:com.google.android.gms@12673008@12.6.73 (020306-194189626):6)

at com.android.okhttp.Connection.upgradeToTls(Connection.java:201)

at com.android.okhttp.Connection.connect(Connection.java:155)

at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:282)

at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:216)

at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:392)

at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:107)

at com.android.okhttp.internal.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:218)

at com.android.okhttp.internal.http.DelegatingHttpsURLConnection.getOutputStream(DelegatingHttpsURLConnection.java:218)

at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:25)

at com.sourcey.materiallogindemo.SignupActivity$4.run(SignupActivity.java:218)

at java.lang.Thread.run(Thread.java:831)

问题是android不再支持SSLv3,因此我确实尝试使用ProviderInstaller.installIfNeeded(getApplicationContext())删除它。 在活动开始时没有用。 所以帮助和感谢

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值