Thursday, October 10, 2013

c# - How to capture JSON response using WebBrowser control - Stack Overflow

Question:
I POST to website's JSON-response URL using WebBrowser.Navigate().
All goes well, including the webBrowser1_DocumentCompleted() event handler being called.
But instead of getting a "quiet" response (e.g. webBrowser1.Document) that I can handle programmatically, I receive a File Download dialog box:
enter image description here
If I click the Save button and later examine the file, it contains exactly the JSON response that I expect.
But I want the program capture this JSON response in-code, without displaying that dialog and having to click the Save button.
How do I capture JSON response using WebBrowser control?

Solution:
-UPDATE-
I just found the solution that will work for me. See the following link for more info but just in case I have pasted the answer here. http://www.codeproject.com/Tips/216175/View-JSON-in-Internet-Explorer
Need to view JSON responses in IE? 1.Open Notepad and paste the following:
Windows Registry Editor Version 5.00;
; Tell IE 7,8,9,10 to open JSON documents in the browser on Windows XP and later.
; 25336920-03F9-11cf-8FD0-00AA00686F13 is the CLSID for the "Browse in place" .
;
[HKEY_CLASSES_ROOT\MIME\Database\Content Type\application/json]
"CLSID"="{25336920-03F9-11cf-8FD0-00AA00686F13}"
"Encoding"=hex:08,00,00,00
2.Save document as IE-Json.reg and then run it.
Note: This has been tested on Windows XP and Windows 7 using IE 7, 8, 9, 10.

No comments: