• 0

[WPF] Alternative to the WebBrowser control?


Question

3 answers to this question

Recommended Posts

  • 0

Are you looking to display the web content direct to the user, or to process the returned HTML response within your own code? If so I've used Net.HttpWebRequest to some good effect, including navigating a website, posting data and obtaining the response data I needed. If you're interested I could post some code.

  • 0
  sathenzar said:
yeah pretty much do the same exact thing like be able to retrieve the html page, manipulate it and be able to make calls between the app and the web page.

Ok well here is a bit of code from an app I'm developing right now that communicates via http/html with another website to retrieve data, it includes logging on via a form based logon system. Its not totally finished, its error checking is quite poor.... but the main thing is it works and you can build on it. Let me know how you get on, and if you find it useful.

Mike

Try

' Set the initial parameters

Dim domain As String = "https://the.website.com"

Dim encoding As New System.Text.ASCIIEncoding

Dim CookieC As New Net.CookieContainer

Dim DataStart As Integer

Dim DataTemp As Integer

' Use the appropriate HTML field names to stuff into the post header

Dim PostData As String = _

"USER=" & Username & _

"&PASSWORD=" & Password & _

"&TARGET=/warranty/ExtendedWarrantyAction.action" & _

"&SMLOCALE=GB-EN" & _

"&SMAUTHREASON=0" & _

"&SiteMinderLogin=yes"

Dim Data() As Byte = encoding.GetBytes(PostData)

' Initialise the request

Dim LoginReq As Net.HttpWebRequest = Net.WebRequest.Create(domain & "/login.fcc")

With LoginReq

.KeepAlive = False

.Method = "POST"

' Note: if the page uses a redirect if will fail

.AllowAutoRedirect = False

.ContentType = "application/x-www-form-urlencoded"

.ContentLength = Data.Length

' Set empty container

.CookieContainer = CookieC

End With

' Add the POST data

Dim SendReq As IO.Stream = LoginReq.GetRequestStream

SendReq.Write(Data, 0, Data.Length)

SendReq.Close()

' Obtain the response

Dim LoginRes As Net.HttpWebResponse = LoginReq.GetResponse()

' Retreive the headers from the request (e.g. the location header)

' Add any returned cookies to the cookie collection

CookieC.Add(LoginRes.Cookies)

PostData = "p_sn=" & IMEI & "&formPart=wave"

Dim SNData() As Byte = encoding.GetBytes(PostData)

LoginReq = Net.WebRequest.Create(domain & "/warrantycheck.action")

With LoginReq

.KeepAlive = False

.Method = "POST"

.ContentType = "application/x-www-form-urlencoded"

.ContentLength = SNData.Length

.AllowAutoRedirect = True

.CookieContainer = CookieC

End With

' Add the POST data

SendReq = LoginReq.GetRequestStream

SendReq.Write(SNData, 0, SNData.Length)

SendReq.Close()

LoginRes = LoginReq.GetResponse()

Dim sReader As IO.StreamReader = New IO.StreamReader(LoginRes.GetResponseStream)

' Locate the warranty data

Dim HTML As String = sReader.ReadToEnd

If InStr(HTML, "not found") Then

Result = -6

Exit Sub

End If

Result = 1

Catch

Result = -7

End Try

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Switch to another OS if you're into tinfoil hat mentality, or just uninstall the app. Oh, wait, even after uninstalling it, can Microsoft still be looking at everything? We'll never know, so, yeah, that's that. If you use Windows, you need to live with those options.
    • Minecraft Chase the Skies update and Vibrant Visuals graphics overhaul lands next week by Pulasthi Ariyasinghe The second major game update of the year for Minecraft is almost here. Mojang today announced that its next Game Drop, Chase the Skies, is landing on June 17. Alongside it, the highly anticipated graphics overhaul, dubbed Vibrant Visuals, will be available too, making the day a rather big occasion for Minecraft fans. The Chase the Skies update has a large number of gameplay features and content, but one of the biggest is the expansion of the Ghast. Now, players will be able to find Happy Ghasts as a tameable mob, letting up to five players ride them on journeys across the skies. To get one, players will have to find small, dehydrated Ghasts near fossil structures in the Nether, then bring it to the overworld and feed it plenty of water. It is also possible to craft dried Ghasts from Nether materials. Other features of this update include a handy player locator bar, better leads functionality, craftable saddles, a new music disc, and more. As for the Vibrant Visuals upgrade, Mojang is touting a visual refresh that lets players witness how lights and shadows affect the Minecraft world. "Fly high with your happy ghast to watch the sunrise reflect on the rippling ocean, make art with shifting shadows, descend into dark depths, or simply sit back and enjoy the vivid beauty of each biome," says the studio. "With updated in-game visuals you’ll see how light and shadow transform the Overworld – water reflects, forests become shaded, fog drifts, and waterfalls glimmer in the light." The currently supported devices for Vibrant Visuals include Xbox Series X|S, Xbox One, PlayStation 4, PlayStation 5, PC, as well as Android (Android: Adreno 640, Mali-G68, Mali-G77, or Xclipse 530 or higher) and iOS (A12 or M1 or higher.)   Unfortunately, the Vibrant Visuals upgrade will only be available on the Bedrock Edition of Minecraft, at least for now. Mojang has said that it plans to bring the visual overhaul to the Java Edition of Minecraft at a later date, but no information or release window has been announced just yet.
    • Once people get use to the square-ish case, they'll probably switch the display to square as well.
    • Why would you think it's not enabled all the time? Because they said so?
  • Recent Achievements

    • One Month Later
      POR2GAL4EVER earned a badge
      One Month Later
    • One Year In
      Orpheus13 earned a badge
      One Year In
    • One Month Later
      Orpheus13 earned a badge
      One Month Later
    • Week One Done
      Orpheus13 earned a badge
      Week One Done
    • Week One Done
      serfegyed earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      560
    2. 2
      ATLien_0
      255
    3. 3
      +Edouard
      163
    4. 4
      +FloatingFatMan
      158
    5. 5
      Michael Scrip
      110
  • Tell a friend

    Love Neowin? Tell a friend!