Hou*_*fly 2 android httpconnection
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);
Run Code Online (Sandbox Code Playgroud)
这给了我一个例外:
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);
Run Code Online (Sandbox Code Playgroud)
Localhost的定义是指托管系统 - 安卓设备本身.除非您尝试联系在Android设备上运行的服务器,否则它将无法为您工作.
遵循那些建议您将127.0.0.1(localhost是其名称)更改为托管模拟器的计算机的转发别名的人的建议.
但请注意,这仅适用于仿真器,而不适用于真实设备.
| 归档时间: |
|
| 查看次数: |
5600 次 |
| 最近记录: |