Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在java中发出HttpClient请求_Java_Arrays_Csv_Apache Httpclient 4.x - Fatal编程技术网

在java中发出HttpClient请求

在java中发出HttpClient请求,java,arrays,csv,apache-httpclient-4.x,Java,Arrays,Csv,Apache Httpclient 4.x,我正在创建一个数据下载程序,自从使用httpClient以来,它一直给我带来问题 此代码将所需的所有变量附加到URL: private void createOpenSession() { String params = new StringBuilder() .append("?u=").append(this.user) .append("&p=").append(this.password) .appen

我正在创建一个数据下载程序,自从使用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
,它都会以一种简单的方式打印出标题(这正是我需要它做的)

这只打印一行
Thisdude:Cool3r
,但当我发出另一个打印长行的请求时,它总是会带来以下错误:

    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()
中做错了什么?
感谢您花费的时间。

我通过调试
currencyPairsRequest()
解决了这个问题。。 这就是我解决这个问题的方法。。。 我将
currencyPairsRequest()
返回类型从
void()
更改为
HttpGet

   private HttpGet createCurrencyPairsRequest(String currencyPairs) throws IOException {
       if (this.sessionId == null) {
           this.refreshSessioId();
       }
       String params = new StringBuilder()
               .append("?id=").append(this.sessionId)
               .append("&c=").append(currencyPairs)
               .append("&f=").append(this.format)
               .toString();
       this.requestCurrencies = new HttpGet(this.target + params);
    return requestCurrencies;
   }
然后,我使用以下命令调用'currencyPairsRequest():

在启动任何请求之前,从
main()。。。
而且,它打印了
null
,这意味着我从昨天起就一直在发送
null
请求。。 因此,我没有使用
requestCurrences
,而是通过调用函数本身并返回其值来更改请求


谢谢大家。

我通过调试
currencyPairsRequest()
解决了这个问题。。 这就是我解决这个问题的方法。。。 我将
currencyPairsRequest()
返回类型从
void()
更改为
HttpGet

   private HttpGet createCurrencyPairsRequest(String currencyPairs) throws IOException {
       if (this.sessionId == null) {
           this.refreshSessioId();
       }
       String params = new StringBuilder()
               .append("?id=").append(this.sessionId)
               .append("&c=").append(currencyPairs)
               .append("&f=").append(this.format)
               .toString();
       this.requestCurrencies = new HttpGet(this.target + params);
    return requestCurrencies;
   }
然后,我使用以下命令调用'currencyPairsRequest():

在启动任何请求之前,从
main()。。。
而且,它打印了
null
,这意味着我从昨天起就一直在发送
null
请求。。 因此,我没有使用
requestCurrences
,而是通过调用函数本身并返回其值来更改请求

谢谢大家

System.out.println(requestCurrencies);