get a website data and display on my web page - asp.net

I am Trying to display a website portion on my web page.and for this i dnt want to use iframe.But any other idea which can get data from a website and then display it on my web page like.
this is website
http://www.sugaronline.com/
and want to display this portion on m y web page
http://i.stack.imgur.com/CVsrh.jpg
Please any one tell me is there any way to do this except using iframe?
Update
Shared Function GetHtmlPage(ByVal strURL As String) As String
Dim strResult As String
Dim objResponse As WebResponse
Dim objRequest As WebRequest = HttpWebRequest.Create(strURL)
objResponse = objRequest.GetResponse()
Using sr As New StreamReader(objResponse.GetResponseStream())
strResult = sr.ReadToEnd()
sr.Close()
End Using
Return strResult
End Function
Dim responses As String = GetHtmlPage(theurl)

Refer existing posts
Using HTTPWebRequest in ASP.NET VB
or simply Google this

If you are using PHP, try using CURL, it is a server side request which fetches the data from the target site and then you can embed it in your page.
On the other hand, if you are using .Net, you can use httpwebrequest to do the same.
In short, you will have to make a server side request from your server to the target website to fetch the data and you can embed that data on your page as if it has come from your website.
Please check out this post
How to use httpwebrequest to pull image from website to local file
Here all you need to do is
when you have the image bytes ready, you need to write those bytes to response but before that, you will have to send proper headers to let the browser understand that you are now going to send the image.

Related

Run a URL in background without opening in browser vb.net on clicking a button

I am using aspx with vb.I have a textbox and a login button.
On clicking this button,if username is correct, I need to run a URL in background without showing in browser.
http://example.com/sms.php?email=username
Username is get from the textbox
Dim url As String
url = "example.com/sms.php?email=" & txtUser.Text
CreateObject("wscript.shell").run(url)
You need to perform an async request to the server. You can use jquery ajax or native XMLHttpRequest to perform it on a client-side. If you want to perform request on a server-side you can use WebRequest or WebClient. Give me to know if you need a detailed example with on of this features.
You can use WebRequest Class or you can use HTTPClient class and Get the response stream from the URL, Then you can parse the response in memmory from the data for example if your data is HTML you can Load it in an XDocument and extract whatever information is required from the response , and it is better to use async and await to access the external Url.
eg
Dim client As HttpClient = New HttpClient()
'Dim urlContents As Byte() = Await client.GetByteArrayAsync(url).

Illegal characters in path asp.net and utf

i want get content of web page but when try to access it show this error
"Illegal characters in path"
my question is how i solve it and there is a better way to get content of a page
now i get content with windows application and webbrowser and have no error but cant do in asp
my code
Dim client As New Net.WebClient
TextBox1.Text = client.DownloadString("www.url.com/")
and content of page is
20141105#5058.00#4850.00#4997.00#4870.00#4920.00#4880.00#13553984180.00#2712255#495;
if i change url to http://www.url.com/ the problem solve but character not support like
`‹�طG[T�ے-تAہ0ءI±°M/ùے«Z✖پ$¼×ى(م´;اy­iص)—½؛‚C%%û`
and i add this code but nor work
client.Encoding = Encoding.UTF8
You should include http:// along with the URL to execute the query(TextBox1.Text = client.DownloadString("www.url.com/")) properly, so your code will be like the following:
Dim client As New Net.WebClient
TextBox1.Text = client.DownloadString("http://url.com/")

Comparing URLs in ASP.NET

I have an application that crawls a web site for unique link urls (i.e. hrefs) and then saves the urls to a database. I will ensure that there is url for each page in the site. Below is the code for getting the string that is saved to the database.
'url is the url obtained from the link's href
Dim uriReturn As Uri = New Uri(url, UriKind.RelativeOrAbsolute)
'Make it absolute if it's relative
If Not uriReturn.IsAbsoluteUri Then
Dim baseUri As New Uri(BaseUrl)
uriReturn = New Uri(baseUri, uriReturn)
End If
Return LCase(uriReturn.ToString)
In another part of the application I have section that queries the database with the url of the current page. Below is the code for getting the current page url.
Dim CurrentURL As String = lcase(HttpContext.Current.Request.Url.AbsoluteUri
My question is can I be sure that I will find a match in the database using the current page url? That is could there be differences in the string obtained from the href and the string returned from the current page even through they point to the same page? Is there a way to convert the urls to ensure they will always match?
Since BaseURl is not defined, can't tell if you got it correct. But BaseUrl should be = Request.Url.
And your
Dim CurrentURL As String = lcase(HttpContext.Current.Request.Url.AbsoluteUri
Since you are doing store/retrieve, I suggests you standardize your methods. In store section, you use uriReturn.ToString(), so in the retrieve section, you should also use ToString() instead of AbsoluteUri.

.Net Streamwriter putting exclamation mark in XML feed

When using HttpWebRequest to submit xml post data to a remote server, it inserts exclamation marks throughout the xml data when it sends it, causing the SOAP server to reject it and abort the connection. I have a HTML form submitter and it submits the xml in a textarea just fine without errors.
Here is my basic page logic for submitting the xml data, I have tried using the byte array as well but got the same errors.
Dim submitPage As HttpWebRequest = WebRequest.Create(requestUrl)
submitPage.Method = "POST"
Dim postData As StringBuilder = New StringBuilder()
postData.Append("Submit+XML=Submit&xmldata=" & System.Web.HttpUtility.UrlEncode(CompiledXML))
Dim writer As StreamWriter = Nothing
submitPage.ContentLength = postData.ToString().Length
writer = New StreamWriter(submitPage.GetRequestStream())
writer.Write(postData.ToString())
writer.Close()
So what happens here is is takes my XML string and puts it in the post but it also puts in exclamation marks about every 10 lines.
I have been working on this problem a couple days with no luck.
This was a bug in PHP on the remote server, where if you had a string over a certain length and you stuff it into the email function without line breaks it puts in exclamation points for you. Very odd behaviour but that was what was happening here.

Emulate Excel Web Query in .net

I need to emulate an Excel Web Query in .net Below is the sample code. I get an Error500 when I attempt to do this in .net, however in Excel it works fine. Any ideas on what I am doing wrong? When I change the URI to a normal website it works fine, and returns the html from the page, which i what i am after. I wonder if the problem lies from the fact that I am trying to return a datatable
Dim oHttpWebRequest As System.Net.HttpWebRequest
Dim oStream As System.IO.Stream
Dim sChunk As String
oHttpWebRequest = (System.Net.HttpWebRequest.Create("http://somesite/foo.jsp"))
Dim oHttpWebResponse As System.Net.WebResponse = oHttpWebRequest.GetResponse()
oStream = oHttpWebResponse.GetResponseStream
sChunk = New System.IO.StreamReader(oStream).ReadToEnd()
oStream.Close()
oHttpWebResponse.Close()
Here is the Query from Excel
WEB
1
http:/somesite/foo.jsp
Selection=DataTable
Formatting=None
PreFormattedTextToColumns=True
ConsecutiveDelimitersAsOne=True
SingleBlockTextImport=False
DisableDateRecognition=False
DisableRedirections=False
Edit
I am getting the error when I getReponse from the server
I found the problem I was having.
I used fiddler to figure out the headers that were being sent via excel and compared those with the headers .net was sending
http://www.fiddler2.com/Fiddler2/version.asp
I had to add the following lines of code to add these two headers in order for it to work
oHttpWebRequest.Headers.Add(HttpRequestHeader.Pragma, "no-cache")
oHttpWebRequest.Headers.Add(HttpRequestHeader.AcceptLanguage, "en-us")

Resources