2
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();


                        nameValuePairs.add(new BasicNameValuePair(
                                "product_name", product_name));
                        nameValuePairs.add(new BasicNameValuePair("brand",
                                brand_product));
                        nameValuePairs.add(new BasicNameValuePair("reference_price",
                                mrp_product));
                        nameValuePairs.add(new BasicNameValuePair("model",
                                model_product));

                        HttpPost httppost = new HttpPost(
                                "http://10.0.2.2/wic3/wic2/product/doadd");

                        httppost.setEntity(new UrlEncodedFormEntity(
                                nameValuePairs));
                        ResponseHandler<String> responseHandler = new BasicResponseHandler();
                        String response = SignUpActivity.httpclient.execute(
                                httppost, responseHandler);
                        Log.d("response", response);

                        Intent intent = new Intent(ShareProductActivity.this, ShareActivity.class);
                        startActivity(intent);

this gives me an exception:

05-07 14:56:19.105: D/exception(1137): org.apache.http.conn.HttpHostConnectException: Connection to http://localhost refused

i searched for this and everyone says change 127.0.0.1 to 10.0.2.2, but i am not using 127.0.0.1 I guess the problem is at this step:

String response = SignUpActivity.httpclient.execute(httppost, responseHandler);
4

2 回答 2

5

根据定义,本地主机是指托管系统 - android 设备本身。除非您尝试联系在 android 设备上运行的服务器,否则它对您不起作用。

听从那些建议您将 127.0.0.1(这是 localhost 的名称)更改为托管模拟器的机器的转发别名的建议。

但是请注意,这仅适用于模拟器,不适用于真实设备。

于 2012-05-07T14:45:49.700 回答
0

有两件事要做。

使用 1http://10.0.2.2:8080/代替您的 IP 地址

关闭您的eclipseavd重新启动它们。

于 2012-05-07T14:29:20.840 回答