安卓&x2B;php也返回null

安卓&x2B;php也返回null,php,android,Php,Android,我需要使用android+php,但php也需要echonull????我不知道哪里有错误?我有搜索一些信息,我检查我有添加线程,我有包括 <uses-permission android:name="android.permission.INTERNET" /> 请给我一些建议 php: 安卓: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);

我需要使用android+php,但php也需要echo
null
????我不知道哪里有错误?我有搜索一些信息,我检查我有添加线程,我有包括

<uses-permission android:name="android.permission.INTERNET" />

请给我一些建议

php:

安卓:

 public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     getActionBar().setDisplayHomeAsUpEnabled(true);
     setContentView(R.layout.foodrestaurdetail);
     Intent intent = this.getIntent();
       name = intent.getStringExtra("name");
       vendor_sn = intent.getStringExtra("vendor_sn");
     Toast.makeText(getApplicationContext(),vendor_sn, Toast.LENGTH_SHORT).show();
     getActionBar().setTitle(name); 

    // setupWebView();//載入Webview
           txtMessage = name;

         Thread t = new Thread(new sendPostRunnable(name));
          t.start();
}


 private String sendPostDataToInternet(String strTxt) {
    // TODO Auto-generated method stub
    HttpPost httpRequest = new HttpPost(MAP_URL);
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("name", strTxt));
    try{
        httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
        HttpResponse httpResponse = new        DefaultHttpClient().execute(httpRequest);
         if (httpResponse.getStatusLine().getStatusCode() == 200){
            String strResult = EntityUtils.toString(httpResponse.getEntity());
            return strResult;

         }

    }catch (ClientProtocolException e){
         Toast.makeText(this, e.getMessage().toString(), Toast.LENGTH_SHORT).show();
         e.printStackTrace();
    }catch (IOException e){
        Toast.makeText(this, e.getMessage().toString(),     Toast.LENGTH_SHORT).show();
         e.printStackTrace();
    } catch (Exception e){
         Toast.makeText(this, e.getMessage().toString(), Toast.LENGTH_SHORT).show();
         e.printStackTrace();
    }

    return null;
}

 class sendPostRunnable implements Runnable{

     String strTxt = null;


     public sendPostRunnable(String strTxt) {
        // TODO Auto-generated constructor stub
            this.strTxt = strTxt;
     }

    @Override
    public void run() {
        // TODO Auto-generated method stub
         String result = sendPostDataToInternet(strTxt);

          mHandler.obtainMessage(REFRESH_DATA, result).sendToTarget();
    }

 }
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
getActionBar().setDisplayHomeAsUpEnabled(true);
setContentView(R.layout.foodrestaurdetail);
Intent=this.getIntent();
name=intent.getStringExtra(“名称”);
供应商编号=intent.getStringExtra(“供应商编号”);
Toast.makeText(getApplicationContext(),vendor\u sn,Toast.LENGTH\u SHORT).show();
getActionBar().setTitle(名称);
//setupWebView()//載入网络视图
txtMessage=名称;
线程t=新线程(新sendPostRunnable(name));
t、 start();
}
私有字符串sendPostDataToInternet(字符串strText){
//TODO自动生成的方法存根
HttpPost httpRequest=新的HttpPost(映射URL);
List params=new ArrayList();
添加(新的BasicNameValuePair(“名称”,strText));
试一试{
setEntity(新的UrlEncodedFormEntity(params,HTTP.UTF_8));
HttpResponse HttpResponse=new DefaultHttpClient().execute(httpRequest);
如果(httpResponse.getStatusLine().getStatusCode()==200){
字符串strResult=EntityUtils.toString(httpResponse.getEntity());
返回strResult;
}
}捕获(客户端协议例外e){
Toast.makeText(例如,getMessage().toString(),Toast.LENGTH_SHORT).show();
e、 printStackTrace();
}捕获(IOE异常){
Toast.makeText(例如,getMessage().toString(),Toast.LENGTH_SHORT).show();
e、 printStackTrace();
}捕获(例外e){
Toast.makeText(例如,getMessage().toString(),Toast.LENGTH_SHORT).show();
e、 printStackTrace();
}
返回null;
}
类sendPostRunnable实现Runnable{
字符串strText=null;
公共sendPostRunnable(字符串strText){
//TODO自动生成的构造函数存根
this.strTxt=strTxt;
}
@凌驾
公开募捐{
//TODO自动生成的方法存根
字符串结果=sendPostDataToInternet(strText);
mHandler.actainMessage(刷新数据,结果).sendToTarget();
}
}

HttpPost已被弃用。我建议使用截击库是简单,容易和有用的

这里有一个例子:

// Tag used to cancel the request
String  tag_string_req = "string_req";



String url = "http://api.androidhive.info/volley/string_response.html";

ProgressDialog pDialog = new ProgressDialog(this);
pDialog.setMessage("Loading...");
pDialog.show();     

StringRequest strReq = new StringRequest(Method.GET,
                url, new Response.Listener<String>() {


                @Override
                public void onResponse(String response) {
                    Log.d(TAG, response.toString());
                    pDialog.hide();

                }
            }, new Response.ErrorListener() {

                @Override
                public void onErrorResponse(VolleyError error) {
                    VolleyLog.d(TAG, "Error: " + error.getMessage());
                    pDialog.hide();
                }
            });
//用于取消请求的标记
String tag_String_req=“String_req”;
字符串url=”http://api.androidhive.info/volley/string_response.html";
ProgressDialog pDialog=新建ProgressDialog(此);
设置消息(“加载…”);
pDialog.show();
StringRequest strReq=新的StringRequest(Method.GET,
url,新的Response.Listener(){
@凌驾
公共void onResponse(字符串响应){
Log.d(TAG,response.toString());
pDialog.hide();
}
},new Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误){
d(标记“Error:+Error.getMessage());
pDialog.hide();
}
});
//将请求添加到请求队列 AppController.getInstance().addToRequestQueue(streq,标记字符串请求)

使用参数的另一个示例:

// Tag used to cancel the request
String tag_json_obj = "json_obj_req";

String url = "http://api.androidhive.info/volley/person_object.json";

ProgressDialog pDialog = new ProgressDialog(this);
pDialog.setMessage("Loading...");
pDialog.show();     

    JsonObjectRequest jsonObjReq = new JsonObjectRequest(Method.POST,
            url, null,
            new Response.Listener<JSONObject>() {

                @Override
                public void onResponse(JSONObject response) {
                    Log.d(TAG, response.toString());
                    pDialog.hide();
                }
            }, new Response.ErrorListener() {

                @Override
                public void onErrorResponse(VolleyError error) {
                    VolleyLog.d(TAG, "Error: " + error.getMessage());
                    pDialog.hide();
                }
            }) {

        @Override
        protected Map<String, String> getParams() {
            Map<String, String> params = new HashMap<String, String>();
            params.put("name", "Androidhive");
            params.put("email", "abc@androidhive.info");
            params.put("password", "password123");

            return params;
        }

    };
//用于取消请求的标记
字符串tag_json_obj=“json_obj_req”;
字符串url=”http://api.androidhive.info/volley/person_object.json";
ProgressDialog pDialog=新建ProgressDialog(此);
设置消息(“加载…”);
pDialog.show();
JsonObjectRequest JSONObjectReq=新的JsonObjectRequest(Method.POST,
url,空,
新的Response.Listener(){
@凌驾
公共void onResponse(JSONObject响应){
Log.d(TAG,response.toString());
pDialog.hide();
}
},new Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误){
d(标记“Error:+Error.getMessage());
pDialog.hide();
}
}) {
@凌驾
受保护的映射getParams(){
Map params=新的HashMap();
参数put(“名称”、“Androidhive”);
参数put(“电子邮件”)abc@androidhive.info");
参数put(“密码”、“密码123”);
返回参数;
}
};
//将请求添加到请求队列 AppController.getInstance().addToRequestQueue(jsonObjReq,tag_json_obj)

以下是一个很好的教程:


你把烤面包叫做抓块。但这是一个线索。这是不可能的。返回e.getMessage()作为结果。
但php也返回null
???我看不到回声。此外,您并不是在阅读php中的回声。那你怎么知道?