问题描述
- asynchttpclient 同时发送了post和get
-
按照官网的代码敲进去,如下,点击登陆按钮,发送一个post请求,用wireshark监测手机数据报,结果发现既出现了post请求,然后又出现了get请求,可是我根本没写get方法呀,我也查了下源码,但是并没有发现有调用get的地方,请问大家是什么情况呀?该怎么解决呢?
代码如下:public class MainActivity extends AppCompatActivity { public static final String url="http://bbs.whu.edu.cn/bbslogin.php"; private RequestParams params;//请求参数 private static AsyncHttpClient myclient; private String use="",pass=""; //因为隐私问题,我先把账号密码删去了,但我实际操作过账号密码没错 private EditText name,passward; private Button login; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); name=(EditText)findViewById(R.id.name); passward=(EditText)findViewById(R.id.passward); login=(Button)findViewById(R.id.login); myclient=new AsyncHttpClient(); login.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { params= new RequestParams(); params.put("id",use); params.put("passwd", pass); params.put("auto", "on"); params.put("webtype", "classic"); myclient.post(url, params, new AsyncHttpResponseHandler() { @Override public void onSuccess(int i, Header[] headers, byte[] bytes) { Toast.makeText(MainActivity.this,String.valueOf(i), Toast.LENGTH_SHORT).show(); for(Header h:headers){ Log.i("HEADER",h.toString()); } Log.i("TAG",bytes.toString()); } @Override public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) { Toast.makeText(MainActivity.this,String.valueOf(i), Toast.LENGTH_SHORT).show(); for(Header h:headers){ Log.i("HEADER",h.toString()); } Log.i("TAG",bytes.toString()); } }); } }); } }
解决方案
HttpURLConnection发送post和get请求
AsyncHttpClient 、HttpURLConnection get/post请求、httpClient
时间: 2025-01-03 07:51:20