Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/192.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
Android使用apache发布和获取数据_Android_Apache_Post_Get - Fatal编程技术网

Android使用apache发布和获取数据

Android使用apache发布和获取数据,android,apache,post,get,Android,Apache,Post,Get,我已经提到这个。。。 ,和链接。。。 他们已指定要传递的url,但未指定要传递的参数。。。 当我实现上面url中给出的代码时,我得到了这个错误。。。我对这件事不熟悉。。 我把这个方法叫做 public void postData() { String res=""; // Create a new HttpClient and Post Header HttpClient httpclient = new DefaultHttpClient(); HttpP

我已经提到这个。。。 ,和链接。。。 他们已指定要传递的url,但未指定要传递的参数。。。 当我实现上面url中给出的代码时,我得到了这个错误。。。我对这件事不熟悉。。 我把这个方法叫做

   public void postData() {
    String res="";
    // Create a new HttpClient and Post Header
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(url);

    try {
        // Add your data
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("username", ""));
        nameValuePairs.add(new BasicNameValuePair("email", ""));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        // Execute HTTP Post Request
        HttpResponse response = httpclient.execute(httppost);
        Log.e("response",""+response);


    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
    } catch (IOException e) {
        // TODO Auto-generated catch block
    }

} 
public void postData(){
字符串res=“”;
//创建一个新的HttpClient和Post头
HttpClient HttpClient=新的DefaultHttpClient();
HttpPost HttpPost=新的HttpPost(url);
试一试{
//添加您的数据
List nameValuePairs=新的ArrayList(2);
添加(新的BasicNameValuePair(“用户名”,“用户名”);
添加(新的BasicNameValuePair(“电子邮件”);
setEntity(新的UrlEncodedFormEntity(nameValuePairs));
//执行HTTP Post请求
HttpResponse response=httpclient.execute(httppost);
Log.e(“响应”,“响应+响应”);
}捕获(客户端协议例外e){
//TODO自动生成的捕捉块
}捕获(IOE异常){
//TODO自动生成的捕捉块
}
} 
请帮帮我。。。
谢谢..

由于您没有包含错误,我认为这是因为您正在阻止UI线程,该线程在旧版本的android上运行良好,但在最新版本中,您必须使用一个来执行post请求

private class MyPostTask extends AsyncTask<URL, Void, Void> {
     protected Long doInBackground(URL... urls) {
         String res="";
        // Create a new HttpClient and Post Header
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(urls.get(0));

        try {
            // Add your data
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
            nameValuePairs.add(new BasicNameValuePair("username", ""));
            nameValuePairs.add(new BasicNameValuePair("email", ""));
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

            // Execute HTTP Post Request
            HttpResponse response = httpclient.execute(httppost);
            Log.e("response",""+response);


        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
        } catch (IOException e) {
            // TODO Auto-generated catch block
        }
     }

     protected void onProgressUpdate(Integer... progress) {
         setProgressPercent(progress[0]);
     }

     protected void onPostExecute(Long result) {
         showDialog("Downloaded " + result + " bytes");
     }
 }

请分享你的代码和你收到的错误谢谢你的快速回复..我发布了我的代码。。请看一看。。
new MyPostTask().execute("http://example.com/foo/bar/");