无法将值与java中的httpResponse进行比较
我是web开发领域的新手,我尝试将用户名和密码发送到php脚本,然后将结果返回为0或1。但返回时我没有对它们进行编码。 我的问题是System.out.println(EntityUtils.toString(entity))在提供正确的用户名和密码时将返回值打印为1,但我无法比较或将该值分配给变量无法将值与java中的httpResponse进行比较,java,json,Java,Json,我是web开发领域的新手,我尝试将用户名和密码发送到php脚本,然后将结果返回为0或1。但返回时我没有对它们进行编码。 我的问题是System.out.println(EntityUtils.toString(entity))在提供正确的用户名和密码时将返回值打印为1,但我无法比较或将该值分配给变量 response = httpclient.execute(httppost); HttpEntity entity = response.getEntity();
response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
System.out.println(EntityUtils.toString(entity));
String s=EntityUtils.toString(entity);
但是,当我尝试比较字符串值时,IDE输出显示尝试从封闭流读取,您的意思是
"1".equals(s);
在执行“System.out.println(EntityUtils.toString(entity))”时,http响应内容已被使用 所以,当您再次调用“实体”时,将出现错误 基于流的http内容,您只能读取一次 以下代码可能会起作用:
response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
String s=EntityUtils.toString(entity);
System.out.println(s);
是的,我编辑了我的代码,它没有产生任何错误消息。然后我输入了这段代码。如果(s==“1”){System.out.println(“passed”);}但所需结果未打印。你能检查一下吗?在添加了这段代码后,我尝试了它并使用了你的代码。它成功了。谢谢response=httpclient.execute(httppost);HttpEntity=response.getEntity();字符串s=EntityUtils.toString(实体);系统输出打印项次;