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.
Related
Background
I am relatively new to using the Webview2 control instead of the built in Webbrowser one. I have successfully made some javascripts that help me log in and authenticate myself to a particular website. Within a table from this website, there are a bunch of images.
My end goal is to have a datatable on my application that has all of these images displayed. So far I have all of the source URLs for each image but just need to convert them to the actual images themselves.
How I used to be able to do it using built in Webbrowser Control
Private Async Function GetBitmapFromLink(ByVal ImagePath As String) As Task(Of Image)
Dim request As System.Net.WebRequest = System.Net.WebRequest.Create(ImagePath)
Dim response As System.Net.WebResponse = Await request.GetResponseAsync()
Dim responseStream As System.IO.Stream = response.GetResponseStream()
Dim Img As New Bitmap(responseStream)
Return Img
End Function
Goal
I would like to be able to do a similar function using the Webview2 control instead but am having a hard time finding similar functions. For example, there is no Webview2.WebRequest. I am guessing that similar functions exist in Webview2 but I am just not able to find them.
My question is: How do I make a similar image download function like the one I have shown for the old built in Webbrowser control?
WebView2 does not have a mechanism to start a web request. However, it does have CoreWebView2.WebResourceResponseReceived which you can use to monitor the responses to web requests made from within the WebView2.
You may be able to CoreWebView2.ExecuteScriptAsync to inject script to start background web requests via fetch() or new Request() and then watch for the result of those with CoreWebView2.WebResourceResponseReceived. In the CoreWebView2WebResourceResponseReceivedEventArgs there is a Response property that has a GetContentAsync() async method that gives you the response stream.
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 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.
Currently I am using VB.net to upload files to BOX API, But having issue overwriting a file. I want to use Version upload But where do I need to add the Path parameter or any other necessary parameters to accomplish this? :
Dim tokenProvider As New TokenProvider(clientID, clientSecret)
boxManager.CreateFile("0", "file_name", (file_Stream))
Thanks
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.