【发布时间】:2015-09-15 11:28:41
【问题描述】:
我正在创建一个数据下载器,自从使用 httpClient 以来一直给我带来问题
此代码将所有需要的变量附加到 URL:
private void createOpenSession() {
String params = new StringBuilder()
.append("?u=").append(this.user)
.append("&p=").append(this.password)
.append("&q=").append(this.qualifier)
.toString();
this.openSession = new HttpGet(this.target + params);
}
每当我调用openSession 时,它都会以简单的方式打印出标题(正是我需要它做的)...
public void start() throws ClientProtocolException, IOException {
try {
HttpResponse response = this.httpClient.execute(this.openSession);
if (response.getStatusLine().getStatusCode() == 200) {
try {
String responseContent = this.readResponse(response);
System.out.println(responseContent);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}}
finally {
createCloseSession();
}
}
这会打印一行Thisdude:coole3r,但是当我发出另一个打印长行的请求时,它总是会带来这个错误:
Exception in thread main
java.lang.IllegalArgumentException: HTTP request may not be null
at org.apache.http.util.Args.notNull(Args.java:54)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:81)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107)
at com.si.data.client.ProxyClient1.start(ProxyClient1.java:72)
at com.si.data.client.IpcClient.main(IpcClient.java:136)
这是给出错误的第二个请求:
private void createCurrencyPairsRequest(String currencyPairs) throws IOException {
if (this.sessionId == null) {
this.refreshSessioId();
}
String params = new StringBuilder()
.append("?id=").append(this.sessionId)
.append("&c=").append(currencyPairs)//The Pairs is an array
.append("&f=").append(this.format)
.toString();
this.requestCurrencies = new HttpGet(this.target + params);
}
我在currencyPairsRequest() 中做错了吗?
感谢您抽出宝贵的时间..
【问题讨论】:
标签: java arrays csv apache-httpclient-4.x