android codeigniter和httppost geting响应

时间:2017-03-22 07:55:01

标签: php android server response

我将一个变量发布到codeigniter框架并获得响应。在localhost中一切正常但是当进入实时服务器时,执行命令给出:主机地址未解析错误。我也尝试了asynctask并且我已经混淆了。 请帮帮我

public class MainActivity extends Activity {
    private InputStream is = null;
    BufferedReader reader=null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        new Send_sms().execute();

    }
    class Send_sms extends AsyncTask<Void,Void,String> {
    public Send_sms() {
      }
    @Override
    protected String doInBackground(Void... params) {
    try {
        ArrayList<NameValuePair> postParameters = new              
          ArrayList<NameValuePair>();
        postParameters.add(new BasicNameValuePair("mobile", "0919"));
        HttpClient client = new DefaultHttpClient();
        String postURL = "http://gsmup.ir/index.php/sendsms";
        HttpPost post = new HttpPost(postURL);
        UrlEncodedFormEntity ent = new 
          UrlEncodedFormEntity(postParameters);
        post.setEntity(ent);
        HttpResponse responsePOST = client.execute(post);
        HttpEntity resEntity = responsePOST.getEntity();
        is = resEntity.getContent();
        BufferedReader r = new BufferedReader(new InputStreamReader(is));
        StringBuilder total = new StringBuilder();
        String line;
        while ((line = r.readLine()) != null) {
            if (!line.equals("faild")) {
                break;
            }
            total.append(line).append('\n');
        }
      } catch(Exception ex)  {
        // TODO Auto-generated catch block
          ex.printStackTrace();
      } 
    return null;
    }
   }
}

0 个答案:

没有答案