求解和服务器通信问题
安卓客户端要和同学利用python写的服务器通信 但是一直不行程序代码:
HttpURLConnection conn = null; URL url = new URL("https://api.smratfarm.tk/client/login"); conn = (HttpURLConnection)url.openConnection(); conn.setRequestMethod("POST"); DataOutputStream out = new DataOutputStream(conn.getOutputStream()); out.writeBytes("username=debuger&password=debuger"); InputStream in = conn.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); StringBuilder response = new StringBuilder(); String line; while ((line = reader.readLine())!= null){ response.append(line); } Message message = new Message(); message.what = 0; message.obj = response.toString(); handler.sendMessage(message); }catch(Exception e) { e.printStackTrace(); } } }).start(); }
流程是这样的我想先post账号和密码过去,看能不能得到token
https://api.smratfarm.tk/client/login
post username password从这个api拿到token
测试用账号密码为debuger debuger
https://api.smratfarm.tk/client/get
post token到这个api,会得到最新的BRI 7位字符
如果token错了会有错误码