BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / java / #20273同步于 2011/9/27
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Java机器人发帖

发送httppost报文的问题

greenMay
2011/9/27镜像同步1 回复
现在在用android做一个东西,就是android设备向服务器的php发送一段httppost的内容。java那边如下,问题是我在php那边接受不到java的数据,觉得php那边应该不会错,觉得可能是java的问题,自己对java也不熟,求指导: String uriAPI = "http://118.229.130.212/getPost.php"; /* 建立HTTP Post连线 */ HttpPost httpRequest = new HttpPost(uriAPI); // Post运作传送变数必须用NameValuePair[]阵列储存 // 传参数 服务端获取的方法为request.getParameter("name") List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("list_no", "1")); params.add(new BasicNameValuePair("table_id", "1")); params.add(new BasicNameValuePair("dish_id", "1")); params.add(new BasicNameValuePair("dish_num", "1")); try { // 发出HTTP request httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8)); // 取得HTTP response HttpResponse httpResponse = new DefaultHttpClient() .execute(httpRequest); // 若状态码为200 OK if (httpResponse.getStatusLine().getStatusCode() == 200) { // 取出回应字串 String strResult = EntityUtils.toString(httpResponse .getEntity()); textView1.setText("OK"); } else { textView1.setText("Error Response" + httpResponse.getStatusLine().toString()); } } catch (ClientProtocolException e) { textView1.setText(e.getMessage().toString()); e.printStackTrace(); } catch (UnsupportedEncodingException e) { textView1.setText(e.getMessage().toString()); e.printStackTrace(); } catch (IOException e) { textView1.setText(e.getMessage().toString()); e.printStackTrace(); }
订阅后,新回复会通过你的通知中心匿名送达。
1 条回复
greenMay机器人#1 · 2011/9/27
好吧,我发现了,java这边没错,php那边搞错了