Android 校园网登陆器登录部分

import android.os.Message;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.Headers;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

class Login {
    String url_home = "http://{{ip地址}}/eportal/InterFace.do?method=login";
public Login(){ System.out.println("6666"); } public boolean sendlogin(String name,String pwd,String type){//账号,密码,网络类型,下面的参数可能也要改 new Thread() { public void run() { OkHttpClient client = new OkHttpClient(); MediaType mform = MediaType.get("application/x-www-form-urlencoded; charset=UTF-8"); RequestBody body = RequestBody.create(mform, "userId="+name+"&password="+pwd+"&service="+type+"&queryString=wlanuserip%253D1d90ec446c6b52bb1b90b47e16ca4355%2526wlanacname%253Deb3dea19c415ccae600bdc9db5d15bde%2526ssid%253De8d247c10c121bb9%2526nasip%253D390c1cf6eea7dfbca3f3f0aca4b4d442%2526mac%253Da773684901d08c8722c2b957adb8736e%2526t%253Dwireless-v2%2526url%253D4be2aa94e61657a37b1da9b0c8748ec5d02391b7ff0383fc&operatorPwd=&operatorUserId=&validcode=&passwordEncrypt=false"); Request request = new Request.Builder() .url(url_home) .addHeader("Host","10.23.2.4") .addHeader("User-Agent","Mozilla/5.0 (Linux; U; Android 10; zh-cn; MIX 3 Build/QKQ1.190828.002) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/89.0.4389.116 Mobile Safari/537.36 XiaoMi/MiuiBrowser/15.5.12") .addHeader("Connection","keep-alive") .addHeader("Accept","*/*") .addHeader("Origin", "http://10.23.2.4") .addHeader("Referer","http://10.23.2.4/eportal/index.jsp?wlanuserip=1d90ec446c6b52bb1602c3fcd2686c40&wlanacname=eb3dea19c415ccae600bdc9db5d15bde&ssid=e8d247c10c121bb9&nasip=390c1cf6eea7dfbca3f3f0aca4b4d442&mac=0698e318861475d1243278b6a821baea&t=wireless-v2&url=4be2aa94e61657a37b1da9b0c8748ec5d02391b7ff0383fc") .addHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8") .addHeader("Accept-Encoding","gzip, deflate") .addHeader("Accept-Language","zh-CN,zh;q=0.9") .post(body) .build(); Call call = client.newCall(request); call.enqueue(new Callback() { @Override public void onFailure(Call call, IOException e) { //... } @Override public void onResponse(Call call, Response response) throws IOException { if(response.isSuccessful()){ String result = response.body().string(); Message tempMsg = MainActivity.handler.obtainMessage(); tempMsg.what = 1; tempMsg.obj = result; MainActivity.handler.sendMessage(tempMsg); System.out.println(result); //处理UI需要切换到UI线程处理 } } }); } }.start(); System.out.println("登录完了"); return true; } }

 

posted @ 2021-11-11 20:36  sunny开始学坏  阅读(677)  评论(0编辑  收藏  举报