📄 httpxmlstreamopener.java
字号:
package com.esri.solutions.jitk.datasources.w3c.http;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
import org.apache.commons.httpclient.methods.PostMethod;
import java.io.IOException;
import java.io.InputStream;
public class HTTPXMLStreamOpener {
public HTTPXMLStreamOpener() {
}
public InputStream openHttpGetStream(String httpGetUrl)
throws HttpException, IOException {
HttpClient httpClient = null;
GetMethod method = null;
httpClient = new HttpClient();
method = new GetMethod(httpGetUrl);
// specify the content type as xml
method.setRequestHeader("Content-Type", "text/xml");
// execute the request
httpClient.executeMethod(method);
return method.getResponseBodyAsStream();
}
public PostMethod openHttpPostStream(String httpPostUrl, InputStream in)
throws HttpException, IOException {
HttpClient httpClient = null;
PostMethod method = null;
httpClient = new HttpClient();
method = new PostMethod(httpPostUrl);
// forward input stream to HTTP request object
method.setRequestEntity(new InputStreamRequestEntity(in));
// specify content type and encoding
// if content encoding is not explicitly specified
// ISO-8859-1 is assumed
method.setRequestHeader("Content-type", "text/xml; charset=ISO-8859-1");
// execute request
httpClient.executeMethod(method);
return method;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -