apache-httpclient-4.x

HttpClient 4.2, Basic Authentication, and AuthScope

人盡茶涼 提交于 2019-12-22 05:17:35
问题 I have an application connecting to sites that require basic authentication. The sites are provided at run time and not known at compile time. I am using HttpClient 4.2. I am not sure if the code below is how I am supposed to specify basic authentication, but the documentation would suggest it is. However, I don't know what to pass in the constructor of AuthScope . I had thought that a null parameter meant that the credentials supplied should be used for all URLs, but it throws a

Enable debug logging for Log4J2 + Apache HttpClient

最后都变了- 提交于 2019-12-22 04:35:53
问题 im trying to activate the debug logging for my Apache HttpClient but cant make it work (getting no logging output at all which is HttpClient related). This is my log4j2 configuration im using at the moment: <?xml version="1.0" encoding="UTF-8"?> <configuration status="OFF"> <appenders> <Console name="console" target="SYSTEM_OUT"> <PatternLayout pattern="%d{HH:mm:ss} [%t] %-5level %logger{36} - %msg%n" /> </Console> <RollingFile name="RollingRandomAccessFile" fileName="logs/test.log"

HttpPost with StringEntity having special characters like ®, seeing ¿½` instead of ®

早过忘川 提交于 2019-12-22 03:43:35
问题 I need to use special characters for stringentity as below. DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url); HttpEntity entity = new StringEntity("test®"); httpPost.setEntity(entity); httpPost.setHeader("Accept-Encoding", "UTF-8"); HttpResponse response = httpClient.execute(httpPost); BufferedReader reader = new BufferedReader(new InputStreamReader((response.getEntity().getContent()))); while ((reader.readLine()) != null) { System.out.println

Trusting an expired certificate [duplicate]

本秂侑毒 提交于 2019-12-22 00:44:51
问题 This question already has answers here : java - ignore expired ssl certificate (3 answers) Closed 4 years ago . My client is failing with the below error while communicating with a https server with an expired cert. While we are in the process of waiting that to be fixed on the server side by renewing, I am wondering if we can by pass this error by adding the expired cert to our own trust store? This allows us to gain some testing time while waiting for the cert to be renewed. US has an end

How to create a Folder with Google Drive REST AP and HTTPClient?

微笑、不失礼 提交于 2019-12-21 23:12:01
问题 I am using Google Drive REST API with HTTPClient to create a folder. The REST API is document here Please note that the REST AP Request executes -- but uses the wrong data: tt creates a new file called "untitled" and puts my json there. I have tried different methods of building the POST request with HTTPClient which execute successfully -- but somehow the Google Drive responds with creating a file and returns this data and ignores POST data that I submit. This is what the server reponds with

Why does me use HttpClients.createDefault() as HttpClient singleton instance execute third request always hang

佐手、 提交于 2019-12-21 22:13:57
问题 All , I create : public static final HttpClient DEFAULT_HTTPCLIENT = HttpClients .createDefault(); for(int i=0 ; i<5; i++){ DEFAULT_HTTPCLIENT.execute(requests[i]); } But when loop is to i =2 , that means just execute first two request , till third request , the client will hang and seems dead loop . I refer some materials , I got may be caused by Http Thread Pool configuration limited . But I know what is standard solutions for this issue ? Since I want to send any request any times, but I

Apache HttpClient in Android extremely slow downloading attachment

好久不见. 提交于 2019-12-21 06:59:17
问题 I am trying to download a zip file using HttpCLient 4 and it is going at around .5 (kilobytes/kilobits)? per minute. The file is less than a MB large, and the download will probably take an hour! Am I doing something wrong? How else should I do this? Here is my current implementation: @Override protected Uri doInBackground(String... params) { publishProgress("Downloading..."); try { HttpPost searchPOST = new HttpPost("http://www.somesite.com/" + searchResult.getURLSuffix()); List

How to update the settings of an HttpClient in httpclient 4.3+?

半城伤御伤魂 提交于 2019-12-21 06:28:40
问题 In httpclient 4.3, if you respect all the deprecations, you must build and configure your HttpClient using an HttpClientBuilder (documentation here). The methods are explicit, they seem easy to use, and HttpClient's interface is clear. But maybe a tad too much. In my own case, I have to inherit Spring's HttpComponentsHttpInvokerRequestExecutor (documentation here). As a consequence, I can easily get the HttpClient , but all I know about this object is that it implements the interface. Since

DefaultHttpClient keep alive connection on multiple requests

末鹿安然 提交于 2019-12-21 06:18:27
问题 I'm using the DefaultHttpClient to make numerous requests to the same URL with basic authentication. Something like this: for (String json: listOfItems) { DefaultHttpClient client = new DefaultHttpClient(); try { client.getCredentialsProvider().setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, "basic"), new UsernamePasswordCredentials(user, pass)); HttpPost request = new HttpPost(path); setHeaders(request); StringEntity se = new StringEntity(json, HTTP

Generating HttpRequest from specific IP in Java

天涯浪子 提交于 2019-12-21 05:42:06
问题 I am using Apache HttpClient for generating Post request and submitting the data. Since remote application relays on IP address of the user that's submitting the data, I want to send post request for user specified IP address. How do I configure this? public static void loginUser(String username, String password, String ip) throws Exception{ try { HttpClient client = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://login.myapp.com/"); // Request parameters and other