gpt4 book ai didi

java - 空GETINPUTSTREAM

转载 作者:行者123 更新时间:2023-12-02 03:17:46 26 4
gpt4 key购买 nike

我正在尝试从 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&objectType=resource&objectTable=res_version_business&objectId=206

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

最佳答案

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

InputStream input = UrlOpenRequest.openStream();

关于java - 空GETINPUTSTREAM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56950227/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com