POST 메서드를 사용하여 HttpClient를 사용하여 스크립트에 문자열을 보냅니다. 스크립트는 잘 작동하지만 테이블에 db가 있는지 여부를 확인합니다. 테이블이 존재하면 "1"이 반향됩니다. 스크립트에 공급되는 테이블이 존재 나던 그 다음 토스트가 비어있는 경우 1, 마지막에 토스트에 표시되어있는 경우 다음 코드 모두에서안드로이드 응답 from script problem
잘
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("//remote//script.php");
List<NameValuePair> pairs = new ArrayList<NameValuePair>();
pairs.add(new BasicNameValuePair("tblname", concatenated));
try
{
post.setEntity(new UrlEncodedFormEntity(pairs));
}
catch (UnsupportedEncodingException e)
{
e.printStackTrace();
}
try
{
HttpResponse response = client.execute(post);
entity = response.getEntity();
res = EntityUtils.toString(entity); //this is now the echo back from the script, "1" means tbl already exists exists
}
catch (ClientProtocolException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
Toast msg1 = Toast.makeText(main.this, res, Toast.LENGTH_LONG);
msg1.setGravity(Gravity.CENTER, msg1.getXOffset()/2, msg1.getYOffset()/2);
msg1.show();
SavePreferences("prefs", concatenated);
//fire the authed intent
startauthedactivity();
}
작동이 올바른 동작입니다 .
응답에 -if-를 적용하면 테이블이 존재하더라도 항상 실제 조건이 호출됩니다. 다음 코드에서 테이블이 존재하면 res는 = 1이어야하고 조건은 true가 아니므로 else 블록은 실행되지만 결코 실행되지 않습니다. 내가 스크립트에 존재하는 테이블을 통과하는 경우에는, 이상하게 다음 토스트 실제로
if(res.equals("1"))
왜에 1 ...
if(res != "1")
{
Toast msg1 = Toast.makeText(main.this, res, Toast.LENGTH_LONG);
msg1.setGravity(Gravity.CENTER, msg1.getXOffset()/2, msg1.getYOffset()/2);
msg1.show();
SavePreferences("prefs", concatenated);
//fire the authed intent
startauthedactivity();
}
else
{
//do nothing
}
가장 빠른 답변 중 2 개입니다. 바로 확인 : D – brux