1
回答
求怎么以HTTPPOST的方式和路由起交互。
终于搞明白,存储TCO原来是这样算的>>>   
public void setssid(String name, String password) {
  Map<String, String> parmas = new HashMap<String, String>();

  parmas.put("Host", "192.168.1.1");// //////
  parmas.put("Content-Type",
    "application/x-www-form-urlencoded; charset=UTF-8");
  parmas.put("Authorization", "Basic Z3Vlc3Q6Z3Vlc3Q=");
  parmas.put("Content-Type", "text/plain; charset=UTF-8");
  DefaultHttpClient client = new DefaultHttpClient();// http客户端
  System.out.println("");
  HttpPost httpPost = new HttpPost(
    "http://192.168.1.1/router/wireless_sec_show_quick_setup.cgi");
//  PostMethod postMethod = new PostMethod(
//    "http://192.168.1.1/router/wireless_sec_show_quick_setup.cgi");
//  postMethod.setRequestBody("AP_SSID="+ name+ "w&wire_enable=1&radio_criterion=10&network_mode=0&network_type=0&channel_width=4&br_enable=1&wire_mac=00-90-4C-01-20-03&region=HK&repeater_SSID=Netcore&channel_band=0&channel_num=0&waln_partition=0&SSID_broadcast=1&status_channel_num=5&noise=128&ap_id=0&port_id=WIFI1");
  ArrayList<BasicNameValuePair> pairs = new ArrayList<BasicNameValuePair>();

  if (parmas != null) {

   Set<String> keys = parmas.keySet();

   for (Iterator<String> i = keys.iterator(); i.hasNext();) {

    String key = (String) i.next();

    pairs.add(new BasicNameValuePair(key, parmas.get(key)));

   }

  }

  try {

   UrlEncodedFormEntity p_entity = new UrlEncodedFormEntity(pairs,
     "utf-8");

   // 将POST数据放入HTTP请求

   httpPost.setEntity(p_entity);
   // 发出实际的HTTP POST请求

   HttpResponse response = client.execute(httpPost);

   HttpEntity entity = response.getEntity();

   InputStream content = entity.getContent();

   String returnConnection = convertStreamToString(content);

   // show.setText(returnConnection);
   System.out.println("returnConnection=" + returnConnection);

  } catch (IllegalStateException e) {

   e.printStackTrace();

  } catch (IOException e) {

   e.printStackTrace();

  }

 }

 private String convertStreamToString(InputStream is) {

  BufferedReader reader = new BufferedReader(new InputStreamReader(is));

  StringBuilder sb = new StringBuilder();

  String line = null;

  try {

   while ((line = reader.readLine()) != null) {

    sb.append(line);
    System.out.println(sb);

   }

  } catch (IOException e) {

   e.printStackTrace();

  } finally {

   try {

    is.close();

   } catch (IOException e) {

    e.printStackTrace();

   }

  }

  return sb.toString();

 }

}

请问我要怎么才能把"AP_SSID="+ name+ "w&wire_enable=1&radio_criterion=10&network_mode=0&network_type=0&channel_width=4&br_enable=1&wire_mac=00-90-4C-01-20-03&region=HK&repeater_SSID=Netcore&channel_band=0&channel_num=0&waln_partition=0&SSID_broadcast=1&status_channel_num=5&noise=128&ap_id=0&port_id=WIFI1"这块数据交给路由器处理啊 ,  我连接他一直返回我<HTML><HEAD><TITLE>401 Unauthorized</TITLE></HEAD><BODY><H1>401 Unauthorized</H1>Your client does not have permission to get URL /router/wireless_sec_show_quick_setup.cgi from this server.这个信息。

求大神支招救命啊,我的这是项目时间快到了~

举报
一路人
发帖于5年前 1回/1K+阅
顶部