Comments (4)
I think you might want to try using a custom connection factory.
That way you could perform the address checks there and return a connection opened to the right URL.
from http-request.
I tried this
class DevBaseUrlResolve implements BaseUrl, ConnectionFactory {
private static final Logger LOGGER = LoggerFactory.getLogger(DevBaseUrlResolve.class);
@Resource private Functions functions;
/**
* {@inheritDoc}
*/
@Override
public String resovleBaseUrl() {
final AbstractPatterns patterns = EnvMyCompany.identity(AbstractPatterns.class, "patterns");
InetAddress address = null;
if (patterns.isValidPattern(EnvMyCompany.baseUrl(), "((ht|f)tp(s?))\\://(?:\\d{1,3}\\.){3}\\d{1,3}")) {
try {
address = InetAddress.getByAddress("http://auth.api.dev.mycompany.com", functions.parseNumberIpAddress(EnvMyCompany.baseUrl(), "\\."));
} catch (UnknownHostException e) {
LOGGER.error(LogMessages.READOBJECT.toString(), e.getMessage());
}
}
return address == null ? EnvMyCompany.baseUrl() : address.getHostName();
}
@Override
public HttpURLConnection create(final URL url) throws IOException {
return handleApiDev(url);
}
private HttpURLConnection handleApiDev(final URL url) throws MalformedURLException,
APIException, IOException {
URL dev = new URL("http://169.34.0.39");
if (url.equals(dev)) {
dev = new URL(resovleBaseUrl());
} else {
throw new APIException("Base url for DEV is incorrect");
}
return (HttpURLConnection) dev.openConnection();
}
@Override
public HttpURLConnection create(final URL url, final Proxy proxy) throws IOException {
return handleApiDev(url);
}
}
I get to wire this here
/**
* {@inheritDoc}
*/
@Override
public HttpRequest postFormRequest(final String payload, final String completeUrl,
final String token) {
HttpRequest request = null;
try {
final URL wsaAuth = new URL(completeUrl);
request = HttpRequest.post(wsaAuth)
.contentType(HttpRequest.CONTENT_TYPE_FORM)
.header(HeaderConst.AGENT_KEY.toString(), HeaderConst.AGENT_VAL.toString())
.acceptGzipEncoding()
.uncompress(true)
.authorization(token)
.acceptJson();
} catch (HttpRequestException e) {
LOGGER.error(Purchase.FAILEDREQUESTMESSAGE.toString(), e.getMessage());
} catch (MalformedURLException e) {
LOGGER.error(Purchase.BADURLMESSAGE.toString(), e.getMessage());
}
request.setConnectionFactory(new DevBaseUrlResolve());
return request.send(payload);
}
however the problem is this, and which is driving me crazy
when I check charles proxy
POST http://169.34.0.39/oauth2/token HTTP/1.1
User-Agent: Java/6_apicore_test13
Content-Type: application/x-www-form-urlencoded
Accept: application/json
Authorization: Basic someYwMbase64valueQ=
Host: 169.34.0.39
Proxy-Connection: keep-alive
Content-Length: 79
I need to see the header Host: http://auth.api.dev.mycompany.com
instead of the incorrect value Host: 169.34.0.39
from http-request.
Actually I just need to see the Host: 169.34.0.39
change to Host: http://auth.api.dev.mycompany.com
and every can be the same
from http-request.
So did you figure this out or are you still having issues getting it to work how you need it?
from http-request.
Related Issues (20)
- How do I add request headers? I saw the accept method which is expecting a string, but I need to add new key,value pairs for headers HOT 3
- MOBILE TOP 10: M5-INSUFFICIENT CRYPTOGRAPHYMOBILE
- Accessing the headers of a request, without starting a connection
- Parameter value contains the character # HOT 1
- How to send request with client certificate ? (not globally configured for every request)
- Support of digest authentication
- how to GET with cookie in headers?
- how to make a http request with session? HOT 1
- "Exception in thread "main" java.lang.IllegalStateException" when useProxy
- project status in 2020
- Correcion en peticiones por GET
- option to log the request and the responses HOT 1
- cannot post multi-part with file HOT 1
- java.io.IOException: Unable to tunnel through proxy. Proxy returns "HTTP/1.1 407 Proxy Authentication Required
- java.io.IOException: Premature EOF
- java.lang.IllegalStateException: Already connected
- hope to support HTTP2.0
- Add pkcs12 certificate to autenticate
- CVE-2019-1010206 HOT 2
- It is recommeded to use `java.net.http.HttpClient` with JDK11 or higher.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from http-request.