简体   繁体   中英

HttpClient migration 3.x to 4.x

I try to migrate my HttpClient library by Apache from 3.1 to 4.1.2. I'm looking for the equivalent of this in 4.1.2:

PostMethod method = new PostMethod(url);        
method.addParameter("login", login);   
method.addParameter("password", password);

I try this, but the server doesn't recognize the request :

HttpPost method = new HttpPost(url);   
MultipartEntity multipartEntity = new MultipartEntity(HttpMultipartMode.STRICT);
multipartEntity.addPart("login", new StringBody(login));
multipartEntity.addPart("password", new StringBody(password));
method.setEntity(multipartEntity);

any ideas ?

Have you tried just setting the parameters instead of creating a multipart request?

HttpParams params = new BasicHttpParams();
params.setParameter("login", login);   
params.setParameter("password", password);

HttpPost method = new HttpPost(url);
method.setParams(params);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM