Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/184.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java HttpPost响应无法读取响应_Java_Android_Http Post - Fatal编程技术网

Java HttpPost响应无法读取响应

Java HttpPost响应无法读取响应,java,android,http-post,Java,Android,Http Post,我正在尝试将文本字段中插入的数据与数据库中的数据进行比较。(登录页面) package com.example.eldermonitoring; 导入java.io.InputStream; 导入java.util.ArrayList; 导入org.apache.http.HttpEntity; 导入org.apache.http.HttpResponse; 导入org.apache.http.NameValuePair; 导入org.apache.http.client.HttpClient;

我正在尝试将文本字段中插入的数据与数据库中的数据进行比较。(登录页面)

package com.example.eldermonitoring;
导入java.io.InputStream;
导入java.util.ArrayList;
导入org.apache.http.HttpEntity;
导入org.apache.http.HttpResponse;
导入org.apache.http.NameValuePair;
导入org.apache.http.client.HttpClient;
导入org.apache.http.client.entity.UrlEncodedFormEntity;
导入org.apache.http.client.methods.HttpPost;
导入org.apache.http.impl.client.DefaultHttpClient;
导入org.apache.http.message.BasicNameValuePair;
导入org.apache.http.util.EntityUtils;
导入android.app.Activity;
导入android.content.Context;
导入android.os.AsyncTask;
导入android.os.Bundle;
导入android.util.Log;
导入android.view.view;
导入android.view.view.OnClickListener;
导入android.widget.Button;
导入android.widget.EditText;
公共类登录页扩展活动{
字符串un_text=null;
字符串pw_text=null;
InputStream=null;
字符串行=null;
字符串结果=null;
int代码;
EditText un=null;
EditText pw=null;
按钮提交=空;
Context=null;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u login\u页面);
上下文=这个;
un=(EditText)findViewById(R.id.txtUsername);
pw=(EditText)findViewById(R.id.txtPassword);
提交=(按钮)findViewById(R.id.btnLogin);
submit.setOnClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图arg0){
un_text=un.getText().toString();
pw_text=pw.getText().toString();
System.out.println(“按此处”);
//tvStatus.setText(“记录”);
新建insertDATA()。执行(“”);
System.out.println(“按这里2”);
}
});
}
类insertDATA扩展异步任务{
@凌驾
受保护的字符串doInBackground(字符串…arg0){
//TODO自动生成的方法存根
系统输出打印项次(“1”);
HttpClient HttpClient=新的DefaultHttpClient();
HttpPost HttpPost=新的HttpPost(“http://ems1b15174.net84.net/AppLogin.php");
setHeader(“用户代理”、“Mozilla/5.0(Macintosh;英特尔Mac OS X 10_9_5)AppleWebKit/537.36(KHTML,如Gecko)Chrome/43.0.2357.81 Safari/537.36”);
试一试{
ArrayList nameValuePairs=新的ArrayList();
添加(新的BasicNameValuePair(“un”,un_文本));
添加(新的BasicNameValuePair(“pw”,pw_文本));
setEntity(新的UrlEncodedFormEntity(nameValuePairs));
HttpResponse response=httpclient.execute(httppost);
HttpEntity当前性=response.getEntity();
if(最近性!=null){
String responsest=EntityUtils.toString(resEntity.trim();
System.out.println(“响应:+responsest”);
//您可以在此处添加if语句,并根据响应执行其他操作
if(responsest==“护理者”)
系统输出打印项次(“CG”);
否则如果(responsest==“nextofkin”)
系统输出打印项次(“NOK”);
其他的
System.out.println(“失败”);
}
}捕获(例外e){
系统输出打印项次(“错误”+e);
}
返回null;
}
}
}
这是我收到的答复。回答是“医务人员”,但是我无法执行if-else语句来查看“了解角色”,以便将其重定向到相应页面。 我认为我的代码在读取响应时有问题,因为响应后面有一个空白。知道为什么会有空的吗

  I/System.out(1106): Press here
  I/System.out(1106): 1
  I/System.out(1106): Press here 2
  I/System.out(1106): Response: caregiver
  I/System.out(1106):       
  I/System.out(1106): <!-- Hosting24 Analytics Code -->
  I/System.out(1106): <script type="text/javascript" src="http://stats.hosting24.com/count.php"></script>
  I/System.out(1106): <!-- End Of Analytics Code -->
  I/System.out(1106): Failed
I/System.out(1106):按此处
I/System.out(1106):1
I/System.out(1106):按此处2
I/System.out(1106):响应:医务人员
输入/输出系统(1106):
输入/输出系统(1106):
输入/输出系统(1106):
输入/输出系统(1106):
I/System.out(1106):失败

试试responseStr.equals(“护理者”)

@John3136如果(responseStr==“护理者”)看起来不像(responseStr.equals(“护理者”)那么相似@John3136在发布之前我已经试过了,但仍然无法确定“无法执行if-else语句”。什么阻止了你?不清楚你在问什么。你应该使用
String.equals()
,不管你怎么说。
  I/System.out(1106): Press here
  I/System.out(1106): 1
  I/System.out(1106): Press here 2
  I/System.out(1106): Response: caregiver
  I/System.out(1106):       
  I/System.out(1106): <!-- Hosting24 Analytics Code -->
  I/System.out(1106): <script type="text/javascript" src="http://stats.hosting24.com/count.php"></script>
  I/System.out(1106): <!-- End Of Analytics Code -->
  I/System.out(1106): Failed