2012-05-07 131 views
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); 

這給了我一個例外:本地主機拒絕

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

我搜索了這一點,大家都說改變127.0.0.110.0.2.2,但我不使用127.0.0.1 我想這個問題是在這步驟:

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

你的http客戶端聲明在哪裏? –

+0

你是否從android mainfest.xml獲得了訪問互聯網的權限? –

+0

我的http客戶端在一些其他類...它是公共靜態....我在每個活動中使用相同的客戶端....除了這個每個活動工作正常。是的,我在我的manifest.xml中添加了互聯網權限 – Housefly

回答

5

本地主機的定義是指託管系統 - 安卓設備本身。除非您嘗試聯繫在Android設備上運行的服務器,否則它不適用於您。

請按照建議您將127.0.0.1(這是localhost的名稱)更改爲承載模擬器的計算機的轉發別名的建議。

但請注意,這隻適用於模擬器而不適用於真正的設備。

+0

謝謝你......但我使用的是10.0.2.2,那是什麼在我的問題中寫道。本地主機不是問題 – Housefly

+0

@ Archie.bpgc如果您聲稱不使用本地主機,那麼爲什麼發佈此錯誤消息:「連接到http:// localhost拒絕」? –

+2

,因爲那是我得到的錯誤....我搜索了它2-3小時n我唯一發現的是localhost或127.0.0.1到10.0.2.2,在我的情況下這很好 – Housefly

0

兩件事情要做。

使用1 http://10.0.2.2:8080/,而不是你的IP地址

閉上你的eclipseavd並重啓。

+0

謝謝你....但我使用10.0.2.2,那是什麼寫在我的問題。本地主機不是問題 – Housefly

相關問題