标签: apache-commons-httpclient

如何配置HTTPClient以对SOCKS代理进行身份验证?

我需要针对SOCKS代理设置代理身份验证.我发现这篇文章提供的说明似乎与常见的HTTP代理一起使用.

        httpclient.getHostConfiguration().setProxy("proxyserver.example.com", 8080);

        HttpState state = new HttpState();
        state.setProxyCredentials(new AuthScope("proxyserver.example.com", 8080), 
           new UsernamePasswordCredentials("username", "password"));
        httpclient.setState(state);
Run Code Online (Sandbox Code Playgroud)

这也适用于SOCKS代理,还是我必须做一些不同的事情?

java proxy http apache-commons-httpclient

5
推荐指数
2
解决办法
2万
查看次数

如何使用 HttpClient 发送 GWT-RPC 请求?

我正在使用 Apache HTTPClient API 发送 HTTPRequest,到目前为止它可以处理标准请求。现在我想发送 GWT-RPC 请求并显示响应,但我总是从 GWT-RPC 服务器收到以下错误:

 //EX[2,1,"com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException/3936916533","This application is out of date, please click the refresh button on your browser. ( Malformed or old RPC message received - expecting version 5 )"],0,5]
Run Code Online (Sandbox Code Playgroud)

实际上,我必须随请求发送以下数据:

5|0|5|http://172.16.103.244:38081/kunagi/scrum.ScrumGwtApplication/|6E611C647A0C98D5A31A2506E16D81D6|scrum.client.ScrumService|startConversation|I|1|2|3|4|1|5|-1|
Run Code Online (Sandbox Code Playgroud)

但我不知道怎么做。

当我从 FireBug 检索请求代码时,我在帖子区域中找到了上述数据作为来源。

java gwt httprequest apache-commons-httpclient

5
推荐指数
1
解决办法
1267
查看次数

HttpRoutePlanner - 它如何与 HTTPS 代理一起工作

我设置了一个 HTTPS 代理,以便 HTTP 客户端可以安全地向代理发送纯 HTTP 请求。例如,客户端可以向代理发送加密的 HTTP GET 请求,代理将删除加密并将纯 HTTP GET 请求发送到终端站点。

我了解到这不是一个常见的设置,只有谷歌浏览器具有支持这种情况的内置功能。(此处的信息 - http://wiki.squid-cache.org/Features/HTTPS#Encrypted_browser-Squid_connection)。我已经让谷歌浏览器与我的 HTTPS 代理一起工作,因此代理端没有问题。

我希望编写一个 HTTP 客户端来加密对我的 HTTPS 代理的所有请求。我尝试通过这种方式将 HTTPS 代理设置为 DefaultHttpClient -

DefaultHttpClient dhc = new DefaultHttpClient();
HttpHost proxy = new HttpHost("192.168.2.3", 8181, "https"); //NOTE : https
dhc.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
Run Code Online (Sandbox Code Playgroud)

然后尝试执行任何请求都会给我一个 SSLPeerUnverifiedException。我不明白为什么。

在探索 DefaultHttpClient API 的过程中,我遇到了 HttpRoutePlanner 和 HttpRoute,我们可以使用它们来指定是否应该加密与代理的连接。但是,我无法完成这项工作。

这是一个图表,通过将它与 HTTP 代理设置区分开来解释我的设置 -

HTTP代理:

HTTP Client <------- Plain Text GET, POST Requests -------> HTTP Proxy <------- Plain Text GET, POST Requests -------> HTTP End-Site

HTTP …
Run Code Online (Sandbox Code Playgroud)

proxy apache-commons-httpclient apache-httpclient-4.x

5
推荐指数
1
解决办法
9517
查看次数

HttpClient 跟随重定向

我目前正在做一个小项目。该项目的目的是登录网站并获取/处理网站上的信息。此外,我想打开一些链接并搜索它们。

服务器端看起来像这样:

您需要登录到一个 php 站点。成功登录后,您将获得一个会话并将被重定向到 foo.username.bar.php(已更改)。

使用此代码:

BufferedReader in = null;
    String data = null;
    try {
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("username",  user));
        nameValuePairs.add(new BasicNameValuePair("passwort", pass));

        HttpClient client = new DefaultHttpClient();
        HttpPost request = new HttpPost(website);
        request.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = client.execute(request);
        in = new BufferedReader(new InputStreamReader(response.getEntity()
                .getContent()));
        StringBuffer sb = new StringBuffer("");
        String l = "";
        String nl = System.getProperty("line.separator");
        while ((l = in.readLine()) != null) {
            sb.append(l + nl);
        }
        in.close();
        data = sb.toString();
        return data; …
Run Code Online (Sandbox Code Playgroud)

php java session web apache-commons-httpclient

5
推荐指数
1
解决办法
4万
查看次数

使用HTTP Commons Client进行基本身份验证

我正在寻找此链接,我正在尝试向服务器发送请求

http://hc.apache.org/httpcomponents-client-ga/tutorial/html/authentication.html

public class Test {
    public static void main(String[] args) throws ClientProtocolException, IOException {

        DefaultHttpClient httpClient;
        URL url = new URL("https://9.5.127.34:443");
        httpClient = getSSLHttpClient(url);
        CredentialsProvider credsProvider = new BasicCredentialsProvider();
        credsProvider.setCredentials(
                new AuthScope("https://9.5.127.34", AuthScope.ANY_PORT),
                new UsernamePasswordCredentials("root", "passw0rd"));


         httpClient.setCredentialsProvider(credsProvider);


        HttpGet httpget = new HttpGet("https://9.5.127.34/powervc/openstack/volume/v1/115e4ad38aef463e8f99991baad1f809//volumes/3627400b-cd98-46c7-a7e2-ebce587a0b05/restricted_metadata");
        HttpResponse response = httpClient.execute(httpget);
        BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        String line = "";
        while ((line = rd.readLine()) != null) {

            System.out.println(line);

            }   
        }
Run Code Online (Sandbox Code Playgroud)

但它给了我错误

Authentication required
Run Code Online (Sandbox Code Playgroud)

请告诉我我做错了什么.Thanx提前

java apache-commons-httpclient

5
推荐指数
1
解决办法
1万
查看次数

Java:将多部分文件发送到 RESTWebservice

我使用Spring作为技术。用于调用Web 服务的 Apache HttpClient。基本目的是上传分段文件(文件不是任何图像文件或视频文件)。但在这里我的要求略有不同。请检查下图。

在此处输入图片说明

在这里你可以看到第一个块。它是一个简单的 GUI,只有 2 个输入标签和正确的表单标签。

在第二个块中,有 RESTFul Webservice,它以 Multipart File 作为参数并对其进行处理。(到此为止已经完成了)。
现在我被困在这里。我想将此多部分文件发送到其他仅使用多部分文件的 RESTFul Web 服务。

RESTFUL Webservice 的代码片段:(评论了一些问题,需要您的建议)

@RequestMapping(value="/project/add")
public @ResponseBody String addURLListToQueue(
        @RequestParam(value = "file") MultipartFile file,
        @RequestParam(value = "id1", defaultValue = "notoken") String projectName,
        @RequestParam(value = "id2", defaultValue = "notoken") String id2,
        @RequestParam(value = "id3", defaultValue = "notoken") String id3){

HttpClient httpclient = new DefaultHttpClient();
httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);

HttpPost httppost = new HttpPost("http://localhost:8080/fs/project/add");

// 1) Do I need to convert …
Run Code Online (Sandbox Code Playgroud)

java spring web-services httpclient apache-commons-httpclient

5
推荐指数
1
解决办法
6177
查看次数

将 commons-httpclient-3.1.jar 升级到 httpclient-4.5.2.jar

由于一些漏洞,我们需要从 commons-httpclient-3.1.jar 移动到 httpclient-4.5.2.jar

现在有一个之前在 3.1 上工作的代码库,但这些方法在 4.5.2 中已弃用。您对如何克服这些错误有任何想法或遇到过

我得到的错误是 1) 无法解析导入 org.apache.commons.httpclient.HostConfiguration 2) 方法 getState() 对于 HttpClient 类型未定义

这是源代码。如果您有任何信息,请告诉我。

import org.apache.axis.MessageContext;

import org.apache.axis.components.net.TransportClientProperties;
import org.apache.axis.components.net.TransportClientPropertiesFactory;
import org.apache.http.auth.Credentials;
import org.apache.commons.httpclient.HostConfiguration;
import org.apache.http.client.HttpClient;
import org.apache.http.auth.NTCredentials;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.auth.AuthScope;
import java.net.URL;


public class CommonsHTTPSender extends
        org.apache.axis.transport.http.CommonsHTTPSender {

    public static final String PROPERTY_PROXY_HOST = "https.proxyHost";
    public static final String PROPERTY_PROXY_PORT = "https.proxyPort";
    public static final String PROPERTY_PROXY_USERNAME = "https.proxyUser";
    public static final String PROPERTY_PROXY_PASSWORD = "https.proxyPassword";

    public CommonsHTTPSender() {
    }

    protected HostConfiguration …
Run Code Online (Sandbox Code Playgroud)

java axis apache-commons-httpclient

5
推荐指数
0
解决办法
1544
查看次数

HttpClient的LocalTestServer移动到哪里?

我已经了解了HttpClient如何LocalTestServer用于自动化测试,但我似乎无法找到它被移动的位置.我尝试httpclient使用tests分类器定义依赖:

'org.apache.httpcomponents:httpclient:4.5.2:tests'
Run Code Online (Sandbox Code Playgroud)

但似乎没有LocalTestServer定义一个类.这已经停止了吗?

java apache-commons-httpclient

5
推荐指数
1
解决办法
1946
查看次数

SocketTimeoutException:读取超时 httpclient

我有一个 REST 服务,每天处理大约 2000 万个请求。我收到以下异常。此问题是间歇性的,我无法将此问题与请求量联系起来。我在周末也遇到了这个例外,当时成交量非常低。我确实通过检查确保没有石碑连接setStaleConnectionCheckEnabled。我在用着httpclient 4.3.4

更新:进一步分析后的一些更多细节 -

从日志中,我可以看到服务在 300 毫秒内响应了大部分请求,但是客户端需要时间连接到服务本身,并且在收到响应时,它已经超过了 6 秒的阈值并进入了读取时间出异常。

getCause(): java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:152)
at java.net.SocketInputStream.read(SocketInputStream.java:122)
at sun.security.ssl.InputRecord.readFully(InputRecord.java:442)
at sun.security.ssl.InputRecord.read(InputRecord.java:480)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:934)
at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:891)
at sun.security.ssl.AppInputStream.read(AppInputStream.java:102)
at org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:139)
at org.apache.http.impl.io.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:155)
at org.apache.http.impl.io.SessionInputBufferImpl.readLine(SessionInputBufferImpl.java:284)
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:140)
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:57)
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:261)
at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:165)
at org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(CPoolProxy.java:167)
at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:272)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:124)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:271)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:71)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:220)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:164)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:139)
at com.sample.SampleClient.doGet(SampleClient.java:137)
Run Code Online (Sandbox Code Playgroud)

客户 …

java sockets connection httpclient apache-commons-httpclient

5
推荐指数
1
解决办法
1万
查看次数

Spring Boot 2.0.1升级后的疯狂HTTP问题

升级到Spring Boot 2.0.1后,我的应用程序遇到了无法解释的问题.

涉及两个应用程序.对App 1的请求向App 2进行后端调用以获取某些数据.对App 2的调用通过AWS弹性负载均衡器(ELB)进行.用于进行调用的客户端是由我的实用程序包装的Apache Commons HttpClient .

在App 1升级到Boot 2.0.1之后,我看到从App 1到App 2的一小部分呼叫都挂了很长时间(15分钟).当我使用JConsole获取挂起线程的线程转储时,我看到了这个堆栈跟踪:

Stack trace: 
java.net.PlainSocketImpl.socketClose0(Native Method)
java.net.AbstractPlainSocketImpl.socketPreClose(AbstractPlainSocketImpl.java:693)
java.net.AbstractPlainSocketImpl.close(AbstractPlainSocketImpl.java:530)
   - locked java.lang.Object@29a91ad3
java.net.SocksSocketImpl.close(SocksSocketImpl.java:1075)
java.net.Socket.close(Socket.java:1495)
   - locked java.lang.Object@71e238ff
   - locked java.net.Socket@73f58606
sun.security.ssl.BaseSSLSocketImpl.close(BaseSSLSocketImpl.java:624)
   - locked sun.security.ssl.SSLSocketImpl@22264f18
sun.security.ssl.SSLSocketImpl.closeSocket(SSLSocketImpl.java:1585)
sun.security.ssl.SSLSocketImpl.closeInternal(SSLSocketImpl.java:1723)
sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:2020)
sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1135)
   - locked sun.security.ssl.SSLSocketImpl@22264f18
   - locked java.lang.Object@4338a60d
sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:940)
sun.security.ssl.AppInputStream.read(AppInputStream.java:105)
   - locked sun.security.ssl.AppInputStream@23fd5b55
org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:137)
org.apache.http.impl.io.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:153)
org.apache.http.impl.BHttpConnectionBase.fillInputBuffer(BHttpConnectionBase.java:344)
org.apache.http.impl.BHttpConnectionBase.isStale(BHttpConnectionBase.java:364)
org.apache.http.impl.conn.CPool.validate(CPool.java:71)
org.apache.http.impl.conn.CPool.validate(CPool.java:45)
org.apache.http.pool.AbstractConnPool$2.get(AbstractConnPool.java:249)
   - locked org.apache.http.pool.AbstractConnPool$2@7c672c9a
org.apache.http.pool.AbstractConnPool$2.get(AbstractConnPool.java:193)
org.apache.http.impl.conn.PoolingHttpClientConnectionManager.leaseConnection(PoolingHttpClientConnectionManager.java:282)
org.apache.http.impl.conn.PoolingHttpClientConnectionManager$1.get(PoolingHttpClientConnectionManager.java:269)
org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:191)
org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185)
org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111)
org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:221)
org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:165)
org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:140)
com.kendelong.util.http.HttpConnectionService.doExecuteAndGetResponse(HttpConnectionService.java:243)
com.kendelong.util.http.HttpConnectionService.getResult(HttpConnectionService.java:189)
com.kendelong.util.http.IHttpConnectionService$getResult$0.call(Unknown Source)
com.hatchbaby.sub.util.MainSiteHttpProxyService.getMemberData(MainSiteHttpProxyService.groovy:68) …
Run Code Online (Sandbox Code Playgroud)

spring apache-commons-httpclient spring-boot

5
推荐指数
1
解决办法
583
查看次数