HTML AGILITY PACK: Using Proxies? - html-agility-pack

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);

Related

ORA-01460: unimplemented or unreasonable conversion (after conversion of a docx to pdf and uploading to db) VisualBasic (VB)

i'm a junior developer and i started working recently.
They put me on this LEGACY program and asked me to try and resolve this problem.
They strictly forbid me of using CLOB.
Dim fs As Stream = PostedFile.InputStream
Dim br As New BinaryReader(fs)
Dim bytes As Byte() = br.ReadBytes(Convert.ToInt32(fs.Length))
pdfComunication = pdfConvert(bytes)
pdfComunication = bytes
idOperator = ViewState("idOperator")
'
Private Function pdfConvert(ByVal document As Byte()) As Byte()
Dim doc As Byte()
Using msRtf As MemoryStream = New MemoryStream(document)
Dim dc As softDocument.DocumentCore = softDocument.DocumentCore.Load(msRtf, New softDocument.DocxLoadOptions())
Using msDocx As MemoryStream = New MemoryStream()
dc.Save(msDocx, New softDocument.PdfSaveOptions())
doc = msDocx.ToArray()
End Using
End Using
Return doc
End Function
'
<WebMethod()>
Public Function InsertComunications(ByVal pIdComunicationType As Integer, ByVal pAwaitingStatus As Integer, ByVal pRequestingUser As String, ByVal pIdSr As String,
ByVal pItem As String, ByVal pText As String, ByVal pCommonSender As String, pPecSender As String, ByVal pDestination As String,
ByVal pPdfComunication As Byte()) As String
Dim dbConn As New OracleConnection
Dim cmd As New OracleCommand
Dim errMsg As String = String.Empty
dbConn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("DBConn").ToString
Try
dbConn.Open()
cmd.Parameters.Clear()
cmd.CommandText = ""
cmd.CommandType = System.Data.CommandType.StoredProcedure
cmd.Connection = dbConn
Dim p_IdComunicationType As New System.Data.OracleClient.OracleParameter("p_IdComunicationType ", System.Data.OracleClient.OracleType.Number)
p_IdComunicationType.Direction = ParameterDirection.Input
p_IdComunicationType.Value = pIdComunicationType
cmd.Parameters.Add(p_IdComunicationType)
Dim p_AwaitingStatus As New System.Data.OracleClient.OracleParameter("p_AwaitingStatus", System.Data.OracleClient.OracleType.Number)
p_AwaitingStatus.Direction = ParameterDirection.Input
p_AwaitingStatus.Value = pAwaitingStatus
cmd.Parameters.Add(p_AwaitingStatus)
Dim p_RequestingUser As New System.Data.OracleClient.OracleParameter("p_RequestingUser ", System.Data.OracleClient.OracleType.NVarChar)
p_RequestingUser.Direction = ParameterDirection.Input
p_RequestingUser.Value = pRequestingUser
cmd.Parameters.Add(p_RequestingUser)
Dim p_IdSr As New System.Data.OracleClient.OracleParameter("p_IdSr", System.Data.OracleClient.OracleType.NVarChar)
p_IdSr.Direction = ParameterDirection.Input
p_IdSr.Value = pIdSr
cmd.Parameters.Add(p_IdSr)
Dim p_Item As New System.Data.OracleClient.OracleParameter("p_Item", System.Data.OracleClient.OracleType.NVarChar)
p_Item.Direction = ParameterDirection.Input
p_Item.Value = pItem
cmd.Parameters.Add(p_Item)
Dim p_Text As New System.Data.OracleClient.OracleParameter("p_Text", System.Data.OracleClient.OracleType.NVarChar)
p_Text.Direction = ParameterDirection.Input
p_Text.Value = pText
cmd.Parameters.Add(p_Text)
Dim p_CommonSender As New System.Data.OracleClient.OracleParameter("p_CommonSender", System.Data.OracleClient.OracleType.NVarChar)
p_CommonSender.Direction = ParameterDirection.Input
p_CommonSender.Value = pCommonSender
cmd.Parameters.Add(p_CommonSender)
Dim p_PecSender As New System.Data.OracleClient.OracleParameter("p_PecSender", System.Data.OracleClient.OracleType.NVarChar)
p_PecSender.Direction = ParameterDirection.Input
p_PecSender.Value = pPecSender
cmd.Parameters.Add(p_PecSender)
Dim p_Destination As New System.Data.OracleClient.OracleParameter("p_Destination", System.Data.OracleClient.OracleType.NVarChar)
p_Destination.Direction = ParameterDirection.Input
p_Destination.Value = pDestination
cmd.Parameters.Add(p_Destination)
Dim p_PdfComunication As New System.Data.OracleClient.OracleParameter("p_PdfComunication", System.Data.OracleClient.OracleType.Blob)
p_PdfComunication.Direction = ParameterDirection.InputOutput
p_PdfComunication.Value = pPdfComunication
cmd.Parameters.Add(p_PdfComunication)
cmd.ExecuteNonQuery()
Finally
dbConn.Dispose()
cmd.Dispose()
End Try
'
The problem is that the file size is too big for the blob in the db, which is strange since in other parts of the program that don't do the conversion it takes files way bigger than the ones i'm trying right now...
Any suggestions?
'EDIT
TYPE t_Cursor IS REF CURSOR;
PROCEDURE GetMailTemplate(Cur_Out OUT t_Cursor);
PROCEDURE 1(p_IdComunicationType IN NUMBER,
p_AwaitingStatus IN NUMBER,
p_RequestingUser IN VARCHAR2,
p_IdSr IN VARCHAR2,
p_Item IN VARCHAR2,
p_Testo IN VARCHAR2,
p_CommonSender IN VARCHAR2,
p_PecSender IN VARCHAR2,
p_Destination IN VARCHAR2,
p_PdfComunication xx.PDF_COMUNICATION%Type
);
PROCEDURE 2( p_AwaytingStatus NUMBER, Cur_Out OUT t_Cursor);
PROCEDURE 3(p_IdComunicationType VARCHAR2,
p_AwaitingStatus NUMBER);
We finally found an answer, we had to put everything inside a TRANSACTION:
Public Function InsertComunications(ByVal pIdComunicationType As Integer, ByVal pAwaitingStatus As Integer, ByVal pRequestingUser As String, ByVal pIdSr As String,
ByVal pItem As String, ByVal pText As String, ByVal pCommonSender As String, pPecSender As String, ByVal pDestination As String,
ByVal pPdfComunication As Byte()) As String
Dim dbConn As New OracleConnection
**Dim trns as System.Data.OracleClient.OracleTransaction = Nothing**
Dim cmd As New OracleCommand
Dim errMsg As String = String.Empty
dbConn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("DBConn").ToString
Try
dbConn.Open()
**trns = dbConn.BeginTransaction**
**cmd.Transaction = trns**
cmd.Parameters.Clear()
cmd.CommandText = ""
cmd.CommandType = System.Data.CommandType.StoredProcedure
cmd.Connection = dbConn
Dim p_IdComunicationType As New System.Data.OracleClient.OracleParameter("p_IdComunicationType ", System.Data.OracleClient.OracleType.Number)
p_IdComunicationType.Direction = ParameterDirection.Input
p_IdComunicationType.Value = pIdComunicationType
cmd.Parameters.Add(p_IdComunicationType)
Dim p_AwaitingStatus As New System.Data.OracleClient.OracleParameter("p_AwaitingStatus", System.Data.OracleClient.OracleType.Number)
p_AwaitingStatus.Direction = ParameterDirection.Input
p_AwaitingStatus.Value = pAwaitingStatus
cmd.Parameters.Add(p_AwaitingStatus)
Dim p_RequestingUser As New System.Data.OracleClient.OracleParameter("p_RequestingUser ", System.Data.OracleClient.OracleType.NVarChar)
p_RequestingUser.Direction = ParameterDirection.Input
p_RequestingUser.Value = pRequestingUser
cmd.Parameters.Add(p_RequestingUser)
Dim p_IdSr As New System.Data.OracleClient.OracleParameter("p_IdSr", System.Data.OracleClient.OracleType.NVarChar)
p_IdSr.Direction = ParameterDirection.Input
p_IdSr.Value = pIdSr
cmd.Parameters.Add(p_IdSr)
Dim p_Item As New System.Data.OracleClient.OracleParameter("p_Item", System.Data.OracleClient.OracleType.NVarChar)
p_Item.Direction = ParameterDirection.Input
p_Item.Value = pItem
cmd.Parameters.Add(p_Item)
Dim p_Text As New System.Data.OracleClient.OracleParameter("p_Text", System.Data.OracleClient.OracleType.NVarChar)
p_Text.Direction = ParameterDirection.Input
p_Text.Value = pText
cmd.Parameters.Add(p_Text)
Dim p_CommonSender As New System.Data.OracleClient.OracleParameter("p_CommonSender", System.Data.OracleClient.OracleType.NVarChar)
p_CommonSender.Direction = ParameterDirection.Input
p_CommonSender.Value = pCommonSender
cmd.Parameters.Add(p_CommonSender)
Dim p_PecSender As New System.Data.OracleClient.OracleParameter("p_PecSender", System.Data.OracleClient.OracleType.NVarChar)
p_PecSender.Direction = ParameterDirection.Input
p_PecSender.Value = pPecSender
cmd.Parameters.Add(p_PecSender)
Dim p_Destination As New System.Data.OracleClient.OracleParameter("p_Destination", System.Data.OracleClient.OracleType.NVarChar)
p_Destination.Direction = ParameterDirection.Input
p_Destination.Value = pDestination
cmd.Parameters.Add(p_Destination)
Dim p_PdfComunication As New System.Data.OracleClient.OracleParameter("p_PdfComunication", System.Data.OracleClient.OracleType.Blob)
p_PdfComunication.Direction = ParameterDirection.InputOutput
p_PdfComunication.Value = pPdfComunication
cmd.Parameters.Add(p_PdfComunication)
cmd.ExecuteNonQuery()
**trns.Commit()**
Finally
dbConn.Dispose()
cmd.Dispose()
End Try

Access to wwwroot - Asp.Net Core MVC working well on local host but not in published app

I'm having a lot of trouble trying to get my App to work when
published. Basically, the code is supposed to create a doc from
template using Open XML sdk, then save to wwwroot and then upload to
blob storage.
It's working fine using local host. Have read and tried some stuff re
accessing static files - but nothing seems to work. Any help would be
very much appreciated. Relevant code is below:
[HttpGet]
public IActionResult GenerateDocxBrowser(MemoryStream mem, string filepath, string inputLastName, string inputTitle, string requestID, string dateReceived, string complaintType, string complaintDetails, string nameString, string no, string street, string town, string postcode)
{
var list = _context.Complaints.Where(s => s.ComplaintId.ToString().Contains(requestID)).ToList();
using (mem = new MemoryStream())
{
filepath = #"wwwroot\RequestTemplate.docx";
nameString = list.Select(s => s.NameString).FirstOrDefault();
complaintDetails = list.Select(s => s.Complaint).FirstOrDefault();
street = list.Select(s => s.AddressStreet).FirstOrDefault();
town = list.Select(s => s.AddressTown).FirstOrDefault();
using (WordprocessingDocument document = WordprocessingDocument.Open(filepath,true))
{
document.GetMergeFields("LastName").ReplaceWithText(inputLastName);
document.GetMergeFields("Title").ReplaceWithText(inputTitle);
document.GetMergeFields("ComplaintID").ReplaceWithText(requestID);
document.GetMergeFields("DateReceived").ReplaceWithText(dateReceived);
document.GetMergeFields("ComplaintType").ReplaceWithText(complaintType);
document.GetMergeFields("ComplaintDetails").ReplaceWithText(complaintDetails);
document.GetMergeFields("NameString").ReplaceWithText(nameString);
document.GetMergeFields("AddressLn1").ReplaceWithText(no + " " + street);
document.GetMergeFields("AddressLn2").ReplaceWithText(town + " TAS " + postcode);
document.SaveAs(#"wwwroot\" + requestID + ".docx");
document.MainDocumentPart.Document.Save();
document.Close();
}
}
const string StorageAccountName = "xxx";
const string StorageAccountKey = "xxxxxx";
var storageAccount = new CloudStorageAccount(
new StorageCredentials(StorageAccountName, StorageAccountKey), true);
var blobClient = storageAccount.CreateCloudBlobClient();
var container = blobClient.GetContainerReference("tasman/Request Images");
CloudBlockBlob blockBlob = container.GetBlockBlobReference(requestID + ".docx");
blockBlob.UploadFromFileAsync(#"wwwroot\" + requestID + ".docx");
return View();
}
Your .SaveAs() field should be relative, currently its literally saving to wwwroot somewhere on the drive. You can specify the relative path a few different ways - one of them is below:
var saveToFolder = Path.Combine(Environment.CurrentDirectory, $"/wwwroot/{requestID}.docx");

Create a Case Sensitive Login Form in VB 10

I want to Create a Login Form that the fields in password are case sensitive example if my passwords is "PassWord" it will only accepts the keyword "PassWord" and not accepts "password" Or "PASSWORD" keyword etc. I want it a character sensitive thanks Please Help me Im a new Programmer using DATABASE MS ACCESS Thanks Here is my code
Private Sub btnLog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLog.Click
Try
Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\NIASecurity.accdb")
Dim cmd As OleDbCommand = New OleDbCommand("SELECT [Username] FROM [Security] WHERE [Username] = #User and Password =#Pass ", con)
cmd.Parameters.AddWithValue("#User", txtUser.Text)
cmd.Parameters.AddWithValue("#Pass", txtPass.Text)
con.Open()
Dim sdr As OleDbDataReader = cmd.ExecuteReader()
If sdr.Read Then
If txtPass.Text = sdr(0) Then
MessageBox.Show("Welcome")
Dim win As New frmAdd
win.MdiParent = frmMDI
win.Show()
Me.Close()
Else
MsgBox("Invalid name or password!")
End If
End If
Catch ex As Exception
MessageBox.Show("Invalid name or password!")
End Try
End Sub
I can say you for save passwords in db, you must save password Data with Hashing Algorithm such as MD5 or SHA1
When user type password for login you hash string that typed for password and compare this string with password that save in db
public static void HashPassword(string Password, out string Salt, out string Hash)
{
System.Security.Cryptography.SHA1Managed sha = new System.Security.Cryptography.SHA1Managed();
Random rnd = new Random();
byte[] s = new byte[20];
rnd.NextBytes(s);
Salt = Convert.ToBase64String(s);
System.Text.UTF8Encoding u = new UTF8Encoding();
byte[] pass = u.GetBytes(Password);
byte[] all = new byte[pass.Length + s.Length];
Array.Copy(pass, all, pass.Length);
Array.Copy(s, 0, all, pass.Length, s.Length);
Byte[] H = sha.ComputeHash(all);
Hash = Convert.ToBase64String(H);
}
public bool IsPasswordCorrect(string Password, string Salt, string Hash)
{
System.Security.Cryptography.SHA1Managed sha = new System.Security.Cryptography.SHA1Managed();
byte[] s = Convert.FromBase64String(Salt);
System.Text.UTF8Encoding u = new UTF8Encoding();
byte[] pass = u.GetBytes(Password);
byte[] all = new byte[pass.Length + s.Length];
Array.Copy(pass, all, pass.Length);
Array.Copy(s, 0, all, pass.Length, s.Length);
Byte[] H = sha.ComputeHash(all);
return (Hash == Convert.ToBase64String(H));
}
now you must use HashPassword method to give hash an salt and save hash and salt to db for every user.
When want to check password use IsPasswordcorrect Method

I want to call java servlet from vb 6.0 button

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

making httpwebrequest using proxy fails

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="*/*"

Resources