Home > Back-end >  Okhttp couldn't get the data
Okhttp couldn't get the data

Time:09-23

I written in python server, using the flask
Code:
 the from flask import flask 

App=Flask (__name__)
@ app. The route ('/getjson ', the methods=[' GET '])
Def getJson () :
Return the open (r "json. TXT", encoding="utf-8"), read ()
='0.0.0.0' app. The run (host, port=8888)

The android client to okhttp3, the code is as follows:
 OkHttpClient client=new OkHttpClient (); 
Request the Request=new Request. The Builder (). The url (url). The method (" GET ", null). The build ();
Call Call=client. NewCall (request);
Call. The enqueue (new Callback () {
@ Override
Public void onFailure (@ NotNull Call Call, @ NotNull IOException e) {
Stars. Prepare ();
Toast. MakeText (Main1Activity. This, "the data load failure", Toast. LENGTH_SHORT), show ();
Stars. The loop ();
}

@ Override
Public void onResponse (@ NotNull Call Call, @ NotNull Response Response) throws IOException {
Json=response. The body (). The string ();

}});
The d (" hello ", "json:" + json);

The question now is I use a mobile browser can access the server, the client can't you see an error, is to return data is empty, make for a long time didn't succeed, please leaders to help,
  • Related