1

httpAsyncClient ライブラリに Cookie を設定しようとしていますが、問題はその例を見つけることができないことです..ここに私のコードがあります。

 public JSONArray sendRequest(List<BasicNameValuePair> postPairs){

    HttpAsyncClient httpclient = null;
    try {
        httpclient = new DefaultHttpAsyncClient();
        httpclient.start();
        HttpPost post = new HttpPost("http://10.0.0.62:8080/IDocWS"+postPairs.get(0).getValue());

        BasicCookieStore cookie = new BasicCookieStore();
        HttpContext httpContext = new BasicHttpContext();
        httpContext.setAttribute(ClientContext.COOKIE_STORE,cookie);

        post.setEntity(new UrlEncodedFormEntity( postPairs, HTTP.UTF_8 ) );
        Future<HttpResponse> future = httpclient.execute(post, null);
        HttpResponse resp = future.get();
        HttpEntity entity = resp.getEntity();
        JSONArray jArray = CovnertToJson(entity);
        return jArray;

ここに私の ConvertToJson メソッドがあります

public JSONArray CovnertToJson(HttpEntity entity){
       try{ 
            InputStream inputStream1= entity.getContent();
            BufferedReader reader1 = new BufferedReader(new InputStreamReader(inputStream1, "UTF-8"));
            StringBuilder sb = new StringBuilder();
            String line1;
            while ((line1 = reader1.readLine()) != null) {
                sb.append(line1);
            }
            JSONArray jArray = new JSONArray(sb.toString());
            return jArray;
       }
4

1 に答える 1