简体   繁体   English

Apache Httppost从服务器Java检索图像

[英]Apache Httppost retrieve image from server Java

Right now I am using Httppost to Post some parameters in the form of xml to a server. 现在,我正在使用Httppost将一些参数以xml的形式发布到服务器。 When the post occurs, a geotiff or .tif file is downloaded. 发生发布时,将下载geotiff或.tif文件。 I have successfully posted the document to the server and successfully downloaded the file simply by attaching the parameters to the url but I can't seem to combine the two. 我已经成功地将文档发布到服务器上,并且仅通过将参数附加到url就成功下载了文件,但是我似乎无法将两者结合起来。 I have to use post because just using the URL leaves out elevation data in the geotiff. 我必须使用post,因为仅使用URL会在geotiff中保留高程数据。

In short, I am not sure how to simultaneously post and retrieve the image of the post. 简而言之,我不确定如何同时发布和检索发布的图片。 This is what I have thus far... 到目前为止,这就是我所拥有的...

// Get target URL
        String strURL = POST;

        // Get file to be posted
        String strXMLFilename = XML_PATH;
        File input = new File(strXMLFilename);

        // Prepare HTTP post
        HttpPost post = new HttpPost(strURL);

        post.setEntity(new InputStreamEntity(
                new FileInputStream(input), input.length()));

        // Specify content type and encoding
        post.setHeader(
                "Content-type", "text/xml");

        // Get HTTP client
        HttpClient httpclient = new DefaultHttpClient();

        //Locate file to store data in
        FileEntity entity = new FileEntity(newTiffFile, ContentType.create("image/geotiff"));

        post.setEntity(entity);

        // Execute request
        try {
            System.out.println("Connecting to Metoc site...\n");

            HttpResponse result = httpclient.execute(post);

I was under the impression that the entity would contain the resulting image. 我的印象是该实体将包含生成的图像。 Any help is much appreciated! 任何帮助深表感谢!

Thanks for the help guys. 感谢您的帮助。 The entity was what was being sent to the server. 该实体就是被发送到服务器的东西。 I had code that was trying to read it from the response as well but it wasn't working because setting the entity to a file entity messed up the post request. 我有一些代码也试图从响应中读取它,但是它不起作用,因为将实体设置为文件实体会弄乱发布请求。 By removing that part, it works great! 删除该部分,效果很好!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM