在java中以附件形式发送XML文件

在java中以附件形式发送XML文件,java,xml,eclipse,restful-url,Java,Xml,Eclipse,Restful Url,我想通过Java类的URL将XML文件作为附件发送 我尝试使用的代码如下所示 File request_XML_file = new File("src/request.xml"); URL url = new URL("https://************?p_xml_file="+request_XML_file); conn = (HttpURLConnection) url.openConnection();

我想通过Java类的URL将XML文件作为附件发送

我尝试使用的代码如下所示

 File request_XML_file = new File("src/request.xml");      
            URL url = new URL("https://************?p_xml_file="+request_XML_file); 
            conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("POST");
            conn.setRequestProperty("enctype","multipart/form-data"); 

但是pxxMLX文件的值是SRC/EXPLAUT.XML

< P>,您也可以考虑java 7

的新特性
Path path = Paths.get("/tmp/foo/bar.txt"); Files.createDirectories(path.getParent()); try { Files.createFile(path); } catch (FileAlreadyExistsException e) { System.err.println("already exists: " + e.getMessage()); } } }
请使用此链接

DefaultHttpClient-httpClient=newdefaulthttpclient();HttpPostRequest=新的HttpPost(“http://localhost:8080/TESTINGrestful/rest/polls/comment"); StringEntity输入=新StringEntity(“…”);setContentType(“text/xml”);setEntity(输入);HttpResponse response=httpClient.execute(postRequest);

经过两天的搜索,我得到了一些有用的东西,这对我很有用。。无需导入任何其他Jar文件。。 如果我们想通过RESTfulWeb服务URL将文件作为附件发送,那么多功能是正确的,为什么要这样做。。
我们走吧。。!!一个现成的代码-->

到底是什么问题?你有例外吗?编译错误或警告?其他一些指示?也不例外,但我将得到的回答是“确保您的XML格式正确且有效”。。。它的RESTFul web服务URL。。服务提供商要求以XML文件的形式发送参数,但我需要的基本内容是。。发送XML文件,就像发送附件一样。。试试这个@亚历克斯:谢谢你的链接。。我用了同样的代码。。。现在给出了一些不同的响应“找不到客户端指定的XML请求文件,或者发现该文件为空”。如何将该文件分配给p_XML_文件参数?请告知此解决方案是否有助于elae,我可以提供另一种选择
DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost postRequest = new HttpPost("http://localhost:8080/TESTINGrestful/rest/polls/comment"); StringEntity input = new StringEntity("<Comment>...</Comment>"); input.setContentType("text/xml"); postRequest.setEntity(input); HttpResponse response = httpClient.execute(postRequest);