如何用post将xml文件发到网络上。求解。。

解决方案 »

  1.   

    xml文件是么?
    Apache的HttpEntity接口有一个实现类FileEntity
    用xml文件生成这个对象,然后HttpClient用post方式通信就好了
      

  2.   

    private DefaultHttpClient httpClient;
    private HttpEntity httpEntity;
    private HttpResponse httpResponse;
    private HttpPost httpPost;

    public void doPost(String url, String filePath)
    {
    try
    {
    httpClient = new DefaultHttpClient();
    httpPost = new HttpPost(url);

    httpEntity = new FileEntity(new File(""), "text/xml");
    httpPost.setEntity(httpEntity);
    httpResponse = httpClient.execute(httpPost);
    } catch (Exception e)
    {

    } finally
    {
    httpClient.getConnectionManager().shutdown();
    }
    }大概就是这样了,httpResponse就是你得到的响应,根据情况再转类型吧
    还有,new FileEntity的第二个参数是contentType,根据你实际上传的文件格式确定