I need to build a client for a web api in VBA and it needs to work behind a proxy (with authentication). I've been looking at the WinHttp.WinHttpRequest and MSXML2.XMLHTTP/ServerXMLHTTP classes. It turns out that:
XMLHTTP automatically detects proxy settings provided through a proxy.pac file (good)
WinHttpRequest doesn't (bad)
However, on the other hand:
XMLHTTP automatically follows redirects, and there's no way of disabling this behaviour (bad)
WinHttpRequest doesn't (good)
Since I'd like to be able to have my cake and eat it, is there a way to get automatic proxy configuration for a component such as WinHttpRequest that doesn't follow redirects blindly?
The VBA-Web project might help you with your pastry eating problem.
https://github.com/VBA-tools/VBA-Web
I guess what you wish to do would go something like:
Dim client As New WebClient
With client
.BaseUrl = "https://www.google.com"
.ProxyUsername = <user>
.ProxyPassword = <password>
.EnableAutoProxy = True
End With
Dim request As New WebRequest
With request
.Method = WebMethod.HttpGet
.Format = WebFormat.PlainText
End With
Dim response As WebResponse
Set response = client.Execute(request)
Related
I am sending http request to sandbox api which sometimes returns positive response but sometimes it returns bad request with same request data and headers. So I want to debug this request using fiddler during I run the .net core code hitting that api.
But I am not able to find any way to that. Can any one please help me out for the same. I have tried following code to do this:
var requestMessage = GenerateRequestMessage(HttpMethod.Put, uri, query);
requestMessage.Content = new ObjectContent<T>(value, new JsonMediaTypeFormatter(), (MediaTypeHeaderValue)null);
IWebProxy proxy = new WebProxy("127.0.0.1", 8888);
HttpClient.DefaultProxy = proxy;
return _httpClient.SendAsync(requestMessage);
but fiddler is not capturing this api request.
I am trying to scrape flashscore.com with VBA using XMLHTTP request. It is making multiple javascript based requests to the server. One request i am interested in (as visible in the chrome developer tools) is this:
but when I send the request, it fails. The code is
With CreateObject("MSXML2.XMLHTTP")
.Open "GET", "https://d.flashscore.com/x/feed/f_1_0_5_en_1", False
.send
End With
Can anybody guide me why i can not retrieve the content like this? Why the request is failing? Thanks
I am fairly new to Restlet and wrote small piece of code to make a HTTP call. It is working but I was wondering how can I add HTTP Connection pooling (apache) into it.
I am not able to find any tutorial or reference code for it.
Client client = new Client(Protocol.HTTP);
ChallengeResponse challengeResponse = new ChallengeResponse(
ChallengeScheme.HTTP_AZURE_SHAREDKEY,
acctName,
accKey);
String url = RestHelper.createRequestURI("CCC");
Request request = new Request(Method.GET, url);
request.setChallengeResponse(challengeResponse);
Response response = client.handle(request);
Any references or help will be appreciated.
In fact, Restlet internally manages a pool at the client connector level. Configuration of this pool can be done using the context of your client. The following example describes to configure it:
Client client = new Client(new Context(), Protocol.HTTP);
client.getContext().getParameters().add("maxConnectionsPerHost","5");
client.getContext().getParameters().add("maxTotalConnections","5");
You can notice that these parameters depend on the underlying client connector you use.
Here are some helpful links:
Doc related to connectors: http://restlet.com/technical-resources/restlet-framework/guide/2.3/core/base/connectors
Javadoc containing parameters for the HTTP client connector: http://restlet.com/technical-resources/restlet-framework/javadocs/2.3/jse/ext/org/restlet/ext/httpclient/HttpClientHelper.html
Notice that if you use ClientResource, you need to share the same client to have only one instance of the client connector under the hood. Otherwise a new one is instantiated for each request. See the way to implement this below:
Client client = new Client(new Context(), Protocol.HTTP);
ClientResource cr = new ClientResource("http://myurl");
cr.setNext(client);
Hope it helps,
Thierry
After implementing a test solution described here :
Use Maven to trigger a wsgen & wsimport in a row, using wsdlLocation
I wonder if there is a way to generate the client jar without knowing the WS URL, so that it would be usable against any similar ws deployed somewhere else.
Any idea?
I wonder if there is a way to generate the client jar without knowing the WS URL, so that it would be usable against any similar ws deployed somewhere else.
Whatever WSDL URI has been used to generate the JAX-WS client artifacts, you can override a service endpoint address from the client code by using the appropriate constructor:
...
URL newEndpoint = new URL("http://new/endpointaddress?wsdl");
QName serviceName = new QName("http://targetNamespaceURI","EchoService");
EchoService service = new EchoService(newEndpoint, serviceName);
Echo port = service.getEchoPort();
System.out.println("Server said: " + echo.echo(args[0]));
...
Related question
How to change webservice url endpoint?
See also
Changing WSDL url (endpoint) in JAX-WS client
I have to connecto TFS via API which already works fine when i am within my lan.
But now i have to connect to a TFS over a webproxy. I am able to connect to the serverstatus.asmx via browser.
I already tried to set a environment variable and added the property to app.config - but without success.
Now i tried to do the same with a httpwebrequest
System.Net.HttpWebRequest request = System.Net.WebRequest.Create(tfs_uri) as System.Net.HttpWebRequest;
request.Credentials = tfs_cred;
System.Net.WebProxy p = new System.Net.WebProxy("http://proxy.local.lan:8080/");
p.UseDefaultCredentials = true;
request.Proxy = p;
System.Net.WebResponse response = request.GetResponse();
This code can connect to the tfs. If i remove proxy definition and add the defaultProxy tag into app.config - i get the same error msg when connecting a TfsConfigurationServer object.
My assumption is: TFS API does not support web proxies. Is this correct?
Can somebody tell me that my assumption is wrong?
You can, but it is a bit more convoluted than just setting the proxy details. Because TFS makes lots of seperate calls under the hood you will not be able to use the methods above.
Try adapting Rido's post below:
http://blogs.msdn.com/b/rido/archive/2010/05/06/how-to-connect-to-tfs-through-authenticated-web-proxy.aspx
I would think that you should be able to integrate this method into your own applicaiton.