1、如:我的http://www.haha.com/submit.htm
<form action="http://www.haha.com/submit.php" method="post" onsubmit="submitTest();> 
   <INPUT name=username value="mytestname">
   <INPUT name=content value="submit some">
   <input type="button"  name="submit">  
</form>
怎么使用android模拟提交这个内容?2、能使用socket来做吗?httpsocket

解决方案 »

  1.   

    建议楼主还是看看http 的post提交方式的,其实这个和以前学习JSP的时候差不多的将你的参数提交给你的地址就OK的
            String baseUrl = http://www.haha.com/submit.htm;
    String nam = name.getText().toString();
    String ag = age.getText().toString();
    NameValuePair nameValuePair1 = new BasicNameValuePair("name", nam);
    NameValuePair nameValuePair2 = new BasicNameValuePair("age", ag);
    List<NameValuePair> list = new ArrayList<NameValuePair>();
    list.add(nameValuePair1);
    list.add(nameValuePair2);
    try {
    HttpEntity requestHttpEntity = new UrlEncodedFormEntity(list);
    HttpPost httpPost = new HttpPost(baseUrl);
    httpPost.setEntity(requestHttpEntity);
    HttpClient httpClient = new DefaultHttpClient();
    httpResponse=httpClient.execute(httpPost);
    entity = httpResponse.getEntity();
    inputstream = entity.getContent();
    BufferedReader reader = new BufferedReader(new InputStreamReader(inputstream));
    String result = null;
    String line = null;
    while((line=reader.readLine())!=null ){
    result = result + line;
    }
    System.out.println("result------"+result);
    System.out.println("response-------"+httpResponse);
    } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
      

  2.   

    1,使用HTTP无疑。
    2,socket逻辑上也可以做,但你需要自己实现HTTP协议(主要是一些必要的头),发往80端口,并自己处理返回,解析HTTP协议,取出返回页面的内容。何必呢?
      

  3.   

    HTTP超时怎么办啊? 有些网络不太好,好像会卡住,要开新线程?
    谢谢!