I am trying to make httpwebrequests using a list of proxy ips, but each time I make a request I get an error message : Unable to connect to the remote server.
Here is a sample of my code:
Dim request as HttpWebRequest = WebRequest.Create(url)
Dim oldProxy as IWebProxy = CType(request.Proxy, IWebProxy)
Dim proxy as New WebProxy()
Dim newuri as new Uri("http://" & proxyIP)
proxy.Address = newuri
request.Proxy = proxy
request.Proxy.Credentials = CredentialCache.DefaultCredentials
Try
request.Timeout=18000
request.UserAgent = useragent
request.KeepAlive = False
**webreponse = tryCast(request.GetResponse(), HttpWebResponse)**
request.accept="*/*"
...
It fails on the request.getresponse line above. Any ideas appreciated.
figured it out changed the code...
Dim request as HttpWebRequest = WebRequest.Create(url)
Dim proxy as New WebProxy()
Dim newuri as new Uri("http://" & proxyIP)
request.Proxy = proxy
Try
request.Method="GET"
request.Timeout=18000
request.UserAgent = useragent
request.KeepAlive = False
**webreponse = tryCast(request.GetResponse(), HttpWebResponse)**
request.accept="*/*"
Related
How do I query objects by attribute (instead of 'Filter Keys') using the Genesys Platform SDK?
Endpoint endpoint = new Endpoint("DEV", "the host", 12020);
endpoint.ServicePrincipalName = "the host/the principle";
_confServerProtocol = new ConfServerProtocol(endpoint);
_confServerProtocol.ClientApplicationType = (int)CfgAppType.CFGSCE;
_confServerProtocol.ClientName = "default";
_confServerProtocol.UserName = "the userid";
_confServerProtocol.Open();
IConfService confService = ConfServiceFactory.CreateConfService(_confServerProtocol);
CfgPersonQuery query = new CfgPersonQuery();
// Need to filter based on an Attribute Value (specifically externalID)
var foo = confService.RetrieveMultipleObjects<CfgPerson>(query);
This worked for me:
CfgXPathBasedQuery query = new CfgXPathBasedQuery(confService, CfgObjectType.CFGPerson, "CfgPerson[#externalID='the value']");
Use below:
Uri uri = new Uri("tcp://Host:Port");
Endpoint endpoint = new Endpoint(Guid.NewGuid().ToString(), uri);
ConfServerProtocol confProtocol = new ConfServerProtocol(endpoint);
confProtocol.ClientApplicationType = (int)CfgAppType.CFGSCE;
confProtocol.ClientName = "default";
confProtocol.UserName = "xxxxxx";
confProtocol.UserPassword = "xxxxxx";
//Channel Open
confProtocol.Open();
IConfService confService = ConfServiceFactory.CreateConfService(confProtocol);
CfgPersonQuery query = new CfgPersonQuery();
query.UserName = "AgentID";
CfgPerson person = confService.RetrieveObjects<CfgPerson>(query);
string ExtID = person.ExternalId;
Note: In this way, Filtering is not possible through ExternalId.
I'm trying to get data from Oracle to a Datatable. My idea was to create a function to do all connection staff and then call it from other parts of the code.
Like:
dt = New DataTable
dt = Oracle2table(sql.ToString)
Then, I created the function:
Function Oracle2table(ByVal sql As String) As DataTable
Oracle2table = Nothing
Try
conn = New OleDb.OleDbConnection(connString)
conn.Open()
cmd = New OleDbCommand(sql, conn)
adaptador = New OleDbDataAdapter
adaptador.SelectCommand = cmd
adaptador.Fill(Oracle2table)
conn.Dispose()
Catch ex As Exception
MessageBox.Show("Error al cargar la tabla. ERROR = " + ex.ToString)
Finally
Oracle2table = Nothing
End Try
End Function
The problem with this code is initialize the variable (Oracle2table = nothing) so i didn't receive a function error.
I am not VB specialist, but this code worked fine, so it may be useful for you:
Dim dt = Oracle2table("select * from dual")
Console.WriteLine(dt.Rows(0)(0))
Function (I removed exception handling for simplicity):
Function Oracle2table(ByVal sql As String) As DataTable
Dim conn = New OleDbConnection(connString)
Oracle2table = New DataTable
conn = New OleDb.OleDbConnection(connString)
conn.Open()
Dim cmd = New OleDbCommand(sql, conn)
Dim adaptador = New OleDbDataAdapter
adaptador.SelectCommand = cmd
adaptador.Fill(Oracle2table)
conn.Dispose()
End Function
I want to call java servlet from from my vb 6.0 code. I have tu use the URL of the servelet on remote machine and display the message after execution of the program.
Private Sub Command3_Click()
Dim req As WinHttp.WinHttpRequest
Dim buffer As Variant
Set req = New WinHttp.WinHttpRequest
req.SetTimeouts 1800000, 1800000, 1800000, 1800000
req.Open "POST", "http://www.google.co.in", False
buffer = "tusharp 0"
req.Send cmbuffer
Debug.Print req.ResponseText
End Sub
Try this.....
Using following bunch of code you can simply call servlet by using URL. You can pass parameters via appropriate method.
**Private Function ExecuteSQL(ByVal sSQL As String, ByVal bResultSet As Boolean) As String
Dim http As Object
Dim strURL As String
Dim strPostData As String
Dim strHeader As String
Dim strResponse As String
On Error GoTo Err
Screen.MousePointer = vbHourglass
Set http = CreateObject("WinHttp.WinHttpRequest.5.1")
strPostData = "?Command=" & IIf(bResultSet, "SELECT", "UPDATE") & "&SQL=" & sSQL
strURL = "http://localhost:8080/FirstProject/DBConnector" & strPostData
http.setTimeouts 10000, 10000, 10000, 10000 'For some reason times out sooner than this sometimes
http.Open "POST", strURL, False
http.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
http.Send strPostData
strResponse = http.ResponseText
Screen.MousePointer = vbDefault
ExecuteSQL = strResponse
Exit Function
How do I use proxies with HAP? This is what I have so far...(with no luck).
IPCHICKEN is just used to test the ip address. it is showing my ip address and not the ip address of my proxy
Function GetPrice(ByVal AmazonURL As String, ByVal Delay As Integer)
Dim aHtml As New HtmlWeb
Dim ChromeAgent As String = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11"
aHtml.UserAgent = ChromeAgent
Dim proxy As New System.Net.WebProxy
Dim proxyAddress As New Uri("http://111.111.111/")
Dim aDoc As HtmlDocument = aHtml.Load("http://www.ipchicken.com", "GET", proxy, System.Net.CredentialCache.DefaultCredentials)
Dim aNode As HtmlAgilityPack.HtmlNode
aNode = aDoc.DocumentNode.SelectSingleNode("//div[#id='olpDivId']/span[2]")
If aNode.InnerText Is Nothing Then
End If
Dim UsedPrice1 As String = aNode.InnerText
Dim i As Integer = UsedPrice1.IndexOf("$")
Dim UsedPrice As Integer = UsedPrice1.Substring(i + 1)
System.Threading.Thread.Sleep(Delay)
Return UsedPrice
End Function
Maybe try something like the following. Depending on the page you mightn't need the UTF8 conversion.
WebProxy proxy = new WebProxy("proxyname", 8080);
proxy.Credentials = CredentialCache.DefaultCredentials;
WebClient client = new WebClient();
client.Proxy = proxy;
string baseHtml = "";
byte[] pageContent = client.DownloadData("your target url");
UTF8Encoding utf = new UTF8Encoding();
baseHtml = utf.GetString(pageContent);
HtmlDocument pageHtml = new HtmlDocument();
pageHtml.LoadHtml(baseHtml);
I am creating a program that auto login into a website using forms authentication. When ever I call my method to connect to the website, it returns me a empty document text. However, if I call the same method a second time, it works perfectly.
Here is my code :
//perform authentication and stores the session in the cookiecontainer
private void loginToSite()
{
// prepare the web page we will be asking for
request = (HttpWebRequest)
WebRequest.Create(#"http://diary.com/notes/my_journal");
request.KeepAlive = true;
//========================================
//start of forms authentication parameters
//========================================
string authInfo = username + ":" + password;
authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
request.Headers["Authorization"] = "Basic " + authInfo;
//========================================
//end of forms authentication parameters
//========================================
request.ContentType = "text/html";
request.Method = "GET";
request.AllowAutoRedirect = true;
request.Referer = #"http://diary.com/";
request.CookieContainer = new CookieContainer();
// execute the request
HttpWebResponse response = (HttpWebResponse)
request.GetResponse();
// we will read data via the response stream
Stream resStream = response.GetResponseStream();
container = request.CookieContainer;
//assign the http content to myWB for manipulation
//myWB is a WebBrowser object that have been declared
myWB.DocumentStream = resStream;
//prevent script errors from popping up
myWB.ScriptErrorsSuppressed = true;
MessageBox.Show(myWB.DocumentText);
}