hi I'm trying to create a spring boot application and I need to send a Post request to Foreign server and I want to send all of the requests with a different IP to other requests I really tried to not ask this question but I did not find anything useful for my problem
I tried to get free proxies from this https://api.getproxylist.com/proxy then connect to them this way :
Proxy proxy = new Proxy(Proxy.Type.SOCKS,new InetSocketAddress("Address",port));
return new OkHttpClient.Builder()
.addInterceptor(interceptor)
.proxy(proxy)
.build();
I expect to connect to the proxy server but I'm getting this two error and I really don't know why :
Malformed reply from SOCKS server
java.io.IOException: unexpected end of stream on null
Related
I'm developing an application on spring boot, however I needed to integrate recaptcha for security purposes on various forms, however the connection always results in a connection timed out, I verified api and the url with postman and it goes through and returns an answer, however on Java code times run out and I get the error java.net.ConnectException: Connection timed out: connect I don't know what I'm doing wrong I use the postman code that provides on "Java OK HTTP". code is the next one.
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url("https://www.google.com/recaptcha/api/siteverify?secret=XX&response=XXX")
.get()
.addHeader("cache-control", "no-cache")
.addHeader("postman-token", "f47548e1-a9e0-9065-7f76-dced294bddcb")
.build();
Response response = client.newCall(request).execute();
However I don't seem to get where the error is, can someone help me?
You have a Connection timed out error, so we can say that:
since this is not an Unknown host error, you must have a DNS that gives an IPv4 or IPv6 address for www.google.com
since this is not a destination unreachable error, you have a route to a gateway and this gateway is a local router that has a default route.
Therefore, the timeout for connect means you have sent a TCP SYN packet to a destination, and this packet has been dropped somewhere in your local network or at the interface between your network and the Internet, in a firewall (since you have not received any ICMP/ICMPv6 packet saying something was wrong - a standard router should have sent you such an information).
The problem is with the first packet (TCP SYN), so your problem can not be relative to your addHeader() calls in your source code. Those headers are never sent, in your case, with this error.
Since www.google.fr has IPv4 and IPv6 addresses, there are two possibilities:
either you have a local IPv6 router that sends RA advertisments, but is not connected to the Internet with IPv6.
Try this to check this case:
replace:
https://www.google.com/recaptcha/api/siteverify?secret=XX&response=XXX
by:
https://[2a00:1450:400c:c04::6a]/recaptcha/api/siteverify?secret=XX&response=XXX
If you continue to get a timeout, this means you have an IPv6 router that is badly configured.
or you have a firewall and need to use a proxy
replace:
https://www.google.com/recaptcha/api/siteverify?secret=XX&response=XXX
by:
https://74.125.206.104/recaptcha/api/siteverify?secret=XX&response=XXX
If you continue to get a timeout, this means you have a firewall and should use a proxy.
I was using Jersey 2.25 client with Jackson, I configured everything correctly in Jersey, it worked normally on my development machine when I ran it in a test class, but Jersey client could never connect to a certain host that we have when deployed on our STG environment and always throws a read timeout exception.
I also know that the problem is not in our environment because I can connect using curl
But when switched to HTTPClient it worked normally.
This is how we created our Jersey Client:
Client client = ClientBuilder.newBuilder()
.register(JacksonFeature.class)
.property(ClientProperties.CONNECT_TIMEOUT,5000)
.property(ClientProperties.READ_TIMEOUT,15000)
.build();
The only difference here is the flow of the app, and also the major change that happens in the flow that could affect the connection is that somewhere before calling the Jersey client another class sets a proxy in the system config:
System.setProperty("http.proxyHost",strProxyHost);
System.setProperty("http.proxyPort",strProxyPort);
System.setProperty("https.proxyHost",strProxyHost);
System.setProperty("https.proxyPort",strProxyPort);
However we can establish a connection normally using HTTPClient:
HttpConnectionManagerParams params = new HttpConnectionManagerParams();
params.setConnectionTimeout(5000);
params.setSoTimeout(10000);
HttpConnectionManager manager = new SimpleHttpConnectionManager();
manager.setParams(params);
HttpClient httpClient = new HttpClient(manager);
We are using HTTPClient 3 because part of this app is legacy and we cannot update the version, but it works normally.
What could be causing this connection problem with Jersey? is there something global that Jersey reads when it's trying to connect?
Jersey by default uses HttpURLConnection and HttpURLConnection uses following global settings for proxy configuration -
System.setProperty("http.proxyHost",strProxyHost);
System.setProperty("http.proxyPort",strProxyPort);
System.setProperty("https.proxyHost",strProxyHost);
System.setProperty("https.proxyPort",strProxyPort);
It means if these system variables are set, Jersey will send all the requests through this configured proxy. Check Details here
However, Apache HttpClient does not follow these settings. For using proxy in Apache HttpClient, you have to use HostConfiguration class. Check details here
So, now to your problem, It looks that your STG environment is not able to connect to specified proxy but able to connect with the service directly.
So, while using Jersey, client is not able to connect to proxy and hence ReadTimeoutException is occurring. Since, you haven't configured HttpClient for using any proxy, it is able to connect with the service directly.
I'm writing a fairly simple Spring Integration flow that processes some data and subsequently sends a message to a websocket that exists in my SSL enabled web server to notify clients of new data.
The initial GET request to my websocket succeeds and the application cert is sent to the server correctly. However when the second request is sent to upgrade the connection to websocket, it no longer sends the application cert and I get a 403 Forbidden server response.
Is there any special configuration in the WebSocketContainer or WebSocketClient that I need to set up to make sure my certificate is always passed to the web server? I'm using STOMP over SockJS for the client.
I'm using netty client now for making http connection, and I have a question when I add https connection in this project.
To add https connection, I've created another pipeline to add SslHandler and attached it to existing client code. Also created new handler for SSL handling and added it to the pipeline.
After then I've added handshake when a bootstrap connection was completed and it was succeed.
However I've got an exception as "java.lang.IllegalArgumentException: invalid version format: OK" when client handler is receiving response data from server.
I've succeed to get a response data for only one of https connection without any exception by simple test code, but when I rebuild it to my project and try to get some http and https connection then it failed.
Could you please let me know how I can fix it and what is the problem?
I want to write a java(SE) program to connect to a proxy server, lets say 123.123.123.123:8080. How am I going to achieve that? What is the protocol between my machine and the proxy server? What is the Java framework's class could be in use?
since java 1.5,you can use java.net.Proxy class to create proxy.
Proxy proxy=new Proxy(Proxy.Type.HTTP, new InetSocketAddress("123.123.123.123", 8080);
URL url = new URL("http://www.example.com");
HttpURLConnection uc = (HttpURLConnection)url.openConnection(proxy);
uc.connect();
reference
The definitive reference for network proxy configuration in Java 5 is this Java Networking and Proxies page.
Yes proxy server is a web server...
Whenever u send a request through your browser to get some resource in the particular web server(say www.google.com),the request is send to the proxy server instead to sending the request directly to the google server..the proxy server process this request,send them to the gooogle server,receives the response and then send the response back to the browser.
Proxy server is basically used to corporate fields to restrict the accesss to specific websites,to keep a track of the internet used by a particular associate,Also it saves some commoonly used webpages in a cache file,so that when another request comes,then instead of connecting to the required server,it get the webpage fron the cache file..Hence it saves the time.Also it scans the incoming data from any server for malware before submitting it to the client(browser).To check if ur company is using proxy server,u can go to the internet explorer setting ->Connections ->LAN Settings