I want to read the content of a .txt file from a URL.
The .txt file content is:
170000082.zip
I am currently using this:
Dim address As String = "http://linktotxt"
Dim client As WebClient = New WebClient()
Dim reader As StreamReader = New StreamReader(client.OpenRead(address))
Label1.Text = reader.ReadToEnd
But it set Label1.Text value to a HTML code and not the content of the txt file.
I do not want to download the txt file locally then read the text of it, I want to get it from the URL.
Any help would be appreciated!
EDIT: Here is the HTML file content:
<html><body><script type="text/javascript" src="/aes.js" ></script><script>function toNumbers(d){var e=[];d.replace(/(..)/g,function(d){e.push(parseInt(d,16))});return e}function toHex(){for(var d=[],d=1==arguments.length&&arguments[0].constructor==Array?arguments[0]:arguments,e="",f=0;f<d.length;f++)e+=(16>d[f]?"0":"")+d[f].toString(16);return e.toLowerCase()}var a=toNumbers("f655ba9d09a112d4968c63579db590b4"),b=toNumbers("98344c2eee86c3994890592585b49f80"),c=toNumbers("b8ff12f43c40961786132a275820f477");document.cookie="__test="+toHex(slowAES.decrypt(c,2,a,b))+"; expires=Thu, 31-Dec-37 23:55:55 GMT; path=/"; location.href="http://I_REMOVED_IT_SORRY/lastfilename.txt?i=1";</script><noscript>This site requires Javascript to work, please enable Javascript in your browser or use a browser with Javascript support</noscript></body></html>
Thanks! :-)
When you visit that address in your browser, the web server first returns html, not a text file. What you're seeing is exactly what you should see after downloading the contents of that address. This html then tells the browser to also download and run some additional javascript (aes.js). It's this javascript that will finally download your text file.
You need to look at the the javascript or monitor your session using your browser's dev tools and find the real address for the text file (possibly http://I_REMOVED_IT_SORRY/lastfilename.txt?i=1).
OK, The same code worked on my new server :-)
Everything is solved now, it was a server problem.
Related
My game relies on a resource folder Located in C's Program Files called 'resources' using pretty basic code to make up the front end of the game
Public Module getItem
Public Item = Image.FromFile("C:\Program Files\GameName\resources\ItemName.gif")
End Module
to get a picture or video, or text as such I'm pulling the request as such for an update
Dim req As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("dropbox link to folder")
Dim res As System.Net.HttpWebResponse = request.GetResponse()
Dim ss As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream())
Dim version As String = ss.ReadToEnd()
so it knows to update but grabbing the entire contents and redownloading it if there's an update in the folder is where im not understanding how i would want to do this in an simple fashion without exhausting memory.
Im familiar with
webclient.DownloadFile("database", FolderName)
This being a method in which you get a .zip folder, which requires unpacking and locating and replacing files and it just feels inefficient.
But if i only make a few changes is there a way to recognize the change and ONLY download the new images that are needed to that resource file without re-downloading everything (300 MB) or if it need be; to re-download everything (replace i suppose), is there a way to unpack the dropbox folder contents that's online into being a download via just picture into the file? I've given thought to the idea of possibly isolating them to a new folder named 'updated content' that just pulls the new pictures/music/videos out each download. Would that be a viable solution? the idea is to throw the new content in the folder to be read. I can just have the EXE updated and with that comes the new code to pull the new content by X method. Doesn't anyone know of a easier way of possibly doing this, i'd like to stick to Dropbox if at all possible.
Any help or advice is greatly appreciated, Thank you.
Central Notes: 'Dropbox Folder Download'
I'm using CasperJS to download a file. I need to extract the filename from the HTTP Response headers (i.e. Content-disposition: attachment;filename="pronk.txt"). There is no way to determine the filename from the URL itself (points to a database hash) or the hyperlink (just says "click here").
CasperJS has a great built-in download() function, however it requires a user-supplied filename. This parameter is not optional, and the download fails without it.
Is there another way to go about this where I can get the file data AND the HTTP headers?
I'm still having the same issue that was previously reported and answered under Microsoft Edge PDF inline issue even though I'm not using the pre-release version of Win 10, but the latest downloaded though Windows Update.
After upgrading my Win 8.1 Machine to Win 10, and tested my ASP.NET application, I faced an issue with displaying inline pdf files.
Here's my C# code in my ASP.NET application:
Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition","inline;filename=some.pdf");
Response.BinaryWrite(pdfArray);
Response.End();
The above works on all browsers, except on Edge where it gives me the following error:
Couldn’t open PDF
Something’s keeping this PDF from opening.
What am I doing wrong?
Copied from my workaround on Microsoft Connect.
WARNING: This is a complete hack and runs the risk of breaking if/when Microsoft ever fixes this issue.
You'll see that Edge issues two requests whenever you view a PDF. To me, it looks like the browser is sending the initial request and then the PDF viewer is issuing its own request when it is opened. If you look at the headers in that second request, you'll see an odd DLNA header coming down, which should just be for media streaming, but that leads me to my workaround...
When the request is received in your handler or page, check if the user agent string contains "Edge/12." If it doesn't, send your PDF back normally. If it does, move on to step #2.
Check if the HTTP Header "GetContentFeatures.DLNA.ORG" exists. If it doesn't, that means that the request came from the browser. Just send back a Content-Type header of "application/pdf" and an empty body. If the header exists, then the request came from the PDF viewer and you can send your PDF back normally.
Basically, the handler treats that first request as a HEAD request and then responds with the full PDF if we determine that the request is coming from the PDF viewer. The risk we run here is if Microsoft removes that DLNA header later on, Edge will not render the PDF properly. Hopefully, Microsoft will fix this issue in their browser and this workaround will not be necessary.
Thanks Dark Helmet, you saved my day.
I implemented the solution in java. Here is the code that might help others.
String userAgent = request.getHeader("user-agent");
System.out.println(userAgent);
if(userAgent.contains("Edge")){
String dlnaHeader = request.getHeader("getcontentfeatures.dlna.org");
System.out.println(dlnaHeader);
if(dlnaHeader == null ){
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] result = baos.toByteArray();
response.setContentType("application/pdf");
response.setHeader("Content-disposition","inline; ");
response.setContentLength(result.length);
ServletOutputStream sos = response.getOutputStream();
sos.write(result);
return null;
}
}
Thanks guys, I just want to put my VB.NET solution here based on your workaround.
Response.Clear()
Response.ClearHeaders()
Response.ClearContent()
Response.Buffer = True
If Request.Headers.Item("User-Agent").Contains("Edge") _
AndAlso IsNothing(Request.Headers.Item("GetContentFeatures.DLNA.ORG")) Then
'Edge? Send empty output if special header not exist
Response.ContentType = "application/pdf"
Dim bTemp As Byte()
Response.BinaryWrite(bTemp) 'Empty output
Response.Flush()
Response.SuppressContent = True
HttpContext.Current.ApplicationInstance.CompleteRequest()
End If
'Normal process:
Response.ContentType = "application/pdf"
Response.BinaryWrite(pdfArray)
Response.Flush()
Response.SuppressContent = True
HttpContext.Current.ApplicationInstance.CompleteRequest()
With Edge 16.16299 (Windows Fall Creator Update) there were made changes here. We did the workaround described in this issue and it worked "well". But now with the new version of Edge (16.16299) it isn’t working anymore and it happens, that the PDFs are corrupted (0 bytes large). Take care if you implemented this workaround somewhere.
What you also take care of is that Edge is doing two requests like before.
I have an MHT (Microsoft web archive) file that I have added to my project folder. I need this file to display in a WebView on a help page. I have set the file's build action to "Content," like this question reccomended. I then use this code in the page's Loaded event handler.
Try
Dim strHelpNavigate = Path.Combine(Windows.ApplicationModel.Package.Current.InstalledLocation.ToString(), "\MyAppsHelp.mht")
webHelp.Navigate(New Uri(strHelpNavigate))
Catch ex As Exception
webHelp.NavigateToString("<html><head><style>body {font-family: segoe ui; color: white; background-color: black;}</style></head><body><h2>Sorry, the help page is currently unavailable.</h2></body></html>")
End Try
This code produces an exception: {"Invalid URI: The format of the URI could not be determined."}
I have also tried passing "\MyAppsHelp.mht" to the Navigate method like this question reccomended, but this produces the same exception, and I see from the Local window that the string passed to the Navigate method is the same either way.
Does anyone have any advice on how to display this file in the WebView?
WebView does not natively support HTML archive files, but you can do the work convert these files to html + images if you're so inclined.
Open the .mht file in notepad, and you'll see that there are separate sections for each part of the HTML file - you can parse these sections to get the HTML out, then the base64 encoded images, then save them in your local app folder and use WebView.NavigateToLocalStreamUri to load them. See http://blogs.msdn.com/b/wsdevsol/archive/2014/06/20/a-primer-on-webview-navigatetolocalstreamuri.aspx for details on how to use this method.
OF course, if it's a static file that you will be using all of the time, it would be far easier to just convert it before packaging the app.
I am trying to navigate to a website with json data using the webbrowser controls but it keeps prompting me to download the file instead of properly navigating to the page as firefox would.
I have tried doing a regular navigate:
frmBrowser.WebBrowser1.Navigate("http://us.wowarmory.com/auctionhouse/money.json")
As well as editing the header content type with many different types:
frmBrowser.WebBrowser1.Navigate("http://us.wowarmory.com/auctionhouse/money.json", "", Nothing, "Content-Type: text/plain" & vbCrLf)
But cant seem to get it working.. Keep in mind I need to use the webbrowser to navigate as you have to be logged in to access this file.
Edit: Also, manually editing my computers registry won't work as I need to distribute this program.
Edit2: Just wanted to add that this code would work if it were the same session, but since it webclient creates a new session it doesn't work
Dim oWeb As New System.Net.WebClient()
oWeb.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
Dim bytArguments As Byte() = System.Text.Encoding.ASCII.GetBytes(params)
Dim bytRetData As Byte() = oWeb.UploadData(url, "POST", bytArguments)
Return System.Text.Encoding.ASCII.GetString(bytRetData)
If your application will allow it, just rename it to money.json.html or something similar. Will download without a problem.