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);
這給了我一個例外:本地主機拒絕
05-07 14:56:19.105: D/exception(1137): org.apache.http.conn.HttpHostConnectException: Connection to http://localhost refused
我搜索了這一點,大家都說改變127.0.0.1
到10.0.2.2
,但我不使用127.0.0.1
我想這個問題是在這步驟:
String response = SignUpActivity.httpclient.execute(httppost, responseHandler);
你的http客戶端聲明在哪裏? –
你是否從android mainfest.xml獲得了訪問互聯網的權限? –
我的http客戶端在一些其他類...它是公共靜態....我在每個活動中使用相同的客戶端....除了這個每個活動工作正常。是的,我在我的manifest.xml中添加了互聯網權限 – Housefly