Skip to content
Advertisement

Tag: http

How to set proxy header in HttpURLConnection

I am trying to build an HTTP request to be sent via a proxy that accepts a proxy header. I am trying to find a way to set that, but couldn’t see it. Below is the curl command which I need to convert to the Java code. curl -i -u user:pwd -k GET –http1.1 –proxy-insecure https://localhost:8443 –proxy-header “X-Connect-Client-Id: abcde” https://target_host/api

How to fetch data from http response entity?

I am using SpringBoot to fetch access Token from my client. I could not separate the Access Token from the responseEntity. Is there a way to Fetch the AccessToken data alone? Here is the code: public ResponseEntity generate_Access_token() { } } The response: Answer Make your life easier, not harder – use plain DTO and then

How to solve KeyError: 400 Bad Request

I have a server to which I want to send post requests in the form of json in Java. But after sending, it gives the answer: “KeyError: 400 Bad Request: The browser (or proxy) send a request that this server could not understand.”. No matter how I change the data, it still gives this error, and the sent requests do

How to read http headers synchronously using BufferedReader?

My problem is that BufferedReader#read() creates an infinite delay until the connection is terminated. As soon as it is interrupted, immediately BufferedReader produces the result. So, because of these delays, I cannot read the headers in sync with the page load. Answer BufferedReader is not the solution, as the name implies, it buffers data by N bytes or until end

Generic restTemplateExchange with generic responseType

I would like to create a own generic method that calls the restTemplate.exchange. In particular I would like that the signature of this generic method to be : I would differentiate what exchange method call according to “responseType” if responseType is Class< T> I call * exchange(URI url, HttpMethod method, HttpEntity<?> requestEntity, Class< T> responseType)* if responseType is ParameterizedTypeReference< T>

Java ProxySelector undefined behaviour

I am experimenting with Proxies in java networking. I have read the documentation regarding them and am currently testing ProxySelector. I notice 2 types of behaviour of this ProxySelector when using with HttpURLConnection & when using with Socket class When using with HttpUrlConnection with this code I get the expected output This makes sense because ports 5000 & 8000 are

Advertisement