空的GENTINPUTSTREAM

时间:2019-07-09 10:09:59

标签: java

我正在尝试从URL获取输入流。 该URL在浏览器上工作正常,因此我获得了所需的信息,如下所示:

<SUCCESS>
<STATUS>ok</STATUS>
<OBJECT_TYPE>resource</OBJECT_TYPE>
<OBJECT_TABLE>res_version_business</OBJECT_TABLE>
<OBJECT_ID>206</OBJECT_ID>
<APP_PATH>start</APP_PATH>
<FILE_CONTENT>
UEsDBBQABgAIAAAAIQA5en1zywEAAGMIAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAAAAAAAAAAAAAAA/hABAGRvY1Byb3BzL2FwcC54bWxQSwUGAAAAABwAHAAwBwAAFhQBAAAA
</FILE_CONTENT>
<FILE_EXTENSION>docx</FILE_EXTENSION>
<ERROR/>
<END_MESSAGE/>
</SUCCESS>

但是在通过打开URL连接进行此操作时,它不起作用。 这是我的代码:

public void sendHttpRequest(String theUrl, String postRequest) throws Exception {
        URL UrlOpenRequest = new URL("http://example.com/docs/modules/content/applet_controller.php?action=editObject&objectType=resource&objectTable=res_version_business&objectId=206");
        System.out.println("UrlOpenRequest: "+UrlOpenRequest.toString());
        HttpURLConnection HttpOpenRequest = (HttpURLConnection) 
        UrlOpenRequest.openConnection();
        HttpOpenRequest.setRequestMethod("POST");
        HttpOpenRequest.setRequestProperty("Accept", "*/*");
        HttpOpenRequest.setDoInput(true);
        HttpOpenRequest.setDoOutput(true);      


        if (!"none".equals(postRequest)) {
            OutputStreamWriter writer = new 
            OutputStreamWriter(HttpOpenRequest.getOutputStream());
            writer.write("fileContent=" + this.fileContentTosend + "&fileExtension=" + this.fileExtension);
            writer.flush();
        } else {
            OutputStreamWriter writer = new 
            OutputStreamWriter(HttpOpenRequest.getOutputStream());
            writer.write("foo=bar");
            writer.flush();
        }
        System.out.println("INPUT STREAM: "+HttpOpenRequest.getInputStream().available());
        this.parse_xml(HttpOpenRequest.getInputStream());
        HttpOpenRequest.disconnect();
    }

 System.out.println("UrlOpenRequest: "+UrlOpenRequest.toString()); 给我这个: http://example.com/docs/modules/content/applet_controller.php?action=editObject&amp;objectType=resource&amp;objectTable=res_version_business&amp;objectId=206

可能是什么问题?它是编码URL问题吗?如果是这样,我该如何解决?

1 个答案:

答案 0 :(得分:0)

要阅读URL后面的内容,您可以执行以下操作:

InputStream input = UrlOpenRequest.openStream();