apache-commons-httpclient

How to use Elasticsearch Rest api in java?

十年热恋 提交于 2019-12-10 17:41:04
问题 I am using Apache Http client for making use of ElasticSearch Rest Api, but I am always getting HTTP error code as 200. Please help Java code import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import java.net.MalformedURLException; import java.util.Scanner; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client

Escaping ampersands in URLs for HttpClient requests

核能气质少年 提交于 2019-12-10 15:06:11
问题 So I've got some Java code that uses Jakarta HttpClient like this: URI aURI = new URI( "http://host/index.php?title=" + title + "&action=edit" ); GetMethod aRequest = new GetMethod( aURI.getEscapedPathQuery()); The problem is that if title includes any ampersands (&), they're considered parameter delimiters and the request goes screwy... and if I replace them with the URL-escaped equivalent %26 , then this gets double-escaped by getEscapedPathQuery() into %2526 . I'm currently working around

HttpClient 403 error when using valid client certificate

北慕城南 提交于 2019-12-09 07:33:24
问题 I'm trying to automate some tasks on a website using Java. I have a valid client for that website (works when I login using firefox), but I keep getting a 403 error when I try to login using http client. Note that I want my trust store to trust anything (I know it's not safe, but at this point I am not worried about that). Here's my code: KeyStore keystore = getKeyStore();//Implemented somewhere else and working ok String password = "changeme"; SSLContext context = SSLContext.getInstance("SSL

outbound-gateway with Basic Authentication in spring-integration

我是研究僧i 提交于 2019-12-07 22:48:03
问题 With spring-integration I would like to call an outbound-gateway with an Basic Authentication. I have something like this : <int-http:inbound-gateway id="versionRequestGateway" supported-methods="POST" request-channel="requestVersionChannel" reply-channel="requestTransformerVersionChannel" path="/consultersite" reply-timeout="10000" request-payload-type="java.lang.String"> </int-http:inbound-gateway> <int-http:outbound-gateway order="1" request-channel="requestVersionChannel" url-expression="

Java - Upload OutputStream as HTTP File Upload

淺唱寂寞╮ 提交于 2019-12-07 14:28:21
问题 I've got a legacy application that writes to an OutputStream , and I'd like to have the contents of this stream uploaded as a file to a Servlet. I've tested the Servlet, which uses commons-fileupload , using JMeter and it works just fine. I would use Apache HttpClient, but it requires a File rather than just an output stream. I can't write a file locally; if there was some in-memory implementation of File perhaps that might work? I've tried using HttpURLConnection (below) but the server

HttpRoutePlanner - How does it work with an HTTPS Proxy

自闭症网瘾萝莉.ら 提交于 2019-12-07 11:33:30
问题 I have an HTTPS proxy set up so that HTTP clients can send plain HTTP requests securely to the proxy. For example, a client can send an encrypted HTTP GET request to the proxy, which will remove the encryption and send the plain HTTP GET request to the end-site. I learned that this is not a common set up and only Google Chrome has in-built features to support such a scenario. (Info here - http://wiki.squid-cache.org/Features/HTTPS#Encrypted_browser-Squid_connection). I have made Google Chrome

Get the final URL of a redirected request with unconventional scheme

◇◆丶佛笑我妖孽 提交于 2019-12-07 09:28:27
问题 My code (below) tries to get the final URL returned from a server that does a bit of redirecting. It works fine as long as the URLs have an http scheme. My problem arises when I want to return a URL with a different scheme. Ultimately I want, in some situations, to return a market:// url or other app launch schemes since this is for Android and I want to start Intents with them. So this gets me as far as retrieving the final http url, but when the final url is market:// it throws the

Downsampling audio from 44.1kHz to 16kHz in Java

徘徊边缘 提交于 2019-12-07 04:47:09
问题 I have an application that records a speech sample from the user's microphone and uploads it to a server which then does some stuff with it. It seems I must record with the following parameters to avoid an IllegalArgumentException : Encoding encoding = AudioFormat.Encoding.PCM_SIGNED; float sampleRate = 44100.0F; int sampleSizeInBits = 16; int channels = 2; int frameSize = 4; float frameRate = 44100.0F; boolean bigEndian = false; But I need to have it recorded at 16khz, not 44.1, (sampleRate

Migrating from HttpClient 3.x to 4.x

被刻印的时光 ゝ 提交于 2019-12-06 16:49:40
问题 We have some code written using commons-httpclient-3.1 that needs to be converted to 4.1. I'm only somewhat familiar with this and am reading the 4.1 httpclient tutorial now. I see a couple of posts here (e.g. Converting from HttpClient 3 to 4 but that's about a specific construct). Seems like there should be some docs/examples somewhere showing how to upgrade usage of 3.x to 4.x ? One specific example: replacing use of org.apache.commons.httpclient.HttpState 回答1: I would replace the library

JAVA: How to create http url connection selecting the ip address to use

天涯浪子 提交于 2019-12-06 13:41:28
I have a pool of public ip addresses configured on my multiple NICs. In my JAVA project, which runs on a LINUX machine, I need to select a specific ip address from the pool and create an HttpURLConnecion using that ip. Further, I will cycle on the pool, using each time a different ip. At the current stage, I was not able to find a solution using the java.net library. I have rather looked at the HttpClient from Apache. At the following link, http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html , it is said that such library can support the functionality I was looking for. A