Android HTTPPOST请求报错
publicvoidregister(Stringurl,StringuserName,StringpassWord){newAsyncTask<String,Void,...
public void register(String url,String userName,String passWord){ new AsyncTask<String, Void, String>(){ @Override protected String doInBackground(String... params) { //分别获取三个参数 1.POST请求地址 2.用户名 3.密码 String url = params[0]; String userName = params[1]; String passWord = params[2]; //建立POST请求 HttpPost post = new HttpPost(url);
try { //POST请求需要接收表单,所以用List作为表单 List<BasicNameValuePair> list = new ArrayList<BasicNameValuePair>(); list.add(new BasicNameValuePair("userName",userName)); list.add(new BasicNameValuePair("passWord",passWord)); post.setEntity(new UrlEncodedFormEntity(list)); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } //HttpResponse try { HttpResponse response = client.execute(post); String result = EntityUtils.toString(response.getEntity()); resultTextView.setText(result); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } }.execute(url); 展开
try { //POST请求需要接收表单,所以用List作为表单 List<BasicNameValuePair> list = new ArrayList<BasicNameValuePair>(); list.add(new BasicNameValuePair("userName",userName)); list.add(new BasicNameValuePair("passWord",passWord)); post.setEntity(new UrlEncodedFormEntity(list)); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } //HttpResponse try { HttpResponse response = client.execute(post); String result = EntityUtils.toString(response.getEntity()); resultTextView.setText(result); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } }.execute(url); 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询