我正在尝试使用HTTP请求连接到mysql数据库。我创建了一个扩展AsyncTask广告的类,该广告负责发出http发布请求并检索数据。这是我的代码:public class AttemptLogin extends AsyncTask { String mUserName; String mPassword; String un = "admin01"; String pass = "admin01"; Connection con; Context context; AlertDialog dialog ; public AttemptLogin(Context context, String mUserName, String Password) { this.context = context; this.mUserName = mUserName; this.mPassword = Password; } @Override protected void onPreExecute(){ dialog = new AlertDialog.Builder(context).create(); dialog.setTitle("Login Status"); } protected void onPostExecute(String s){ dialog.setMessage(s); dialog.show(); } @Override protected Object doInBackground(Object[] objects) { try{ Log.d(tag, "Debut do in background"); String constr = "http://000.000.0.00:3306/login.php"; URL url = new URL(constr); HttpURLConnection http = (HttpURLConnection)url.openConnection(); http.setDoInput(true); http.setDoOutput(true); http.setUseCaches(false); http.setRequestMethod("POST"); http.setRequestProperty("Connection", "close"); OutputStream ops = http.getOutputStream(); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(ops,"UTF-8"));当然,我放置的IP只是为了隐藏我的真实IP。无论如何,getInputStream()处的行返回以下错误:意外的状态行:Y我尝试了很多事情,包括将“ Connection”属性设置为“ close”,但没有成功。任何帮助将不胜感激,因为我已经停滞了一段时间。谢谢!
- 1 回答
- 0 关注
- 190 浏览
添加回答
举报
0/150
提交
取消