Getting text from WebBrowser response

The webbrowser component is properly sending and receiving. The result that I get is visible within the browser window. It is XML text, and I would like to load this information into a TMemo. I have tried different techniques suggested on the Internet, including the one shown below. However, I either get nothing in the TMemo, or I get:   ÿþ<   

Any suggestions? (I have tried using the idhttp component, but I am not getting anything in response.) I am using Delphi 5.

procedure TForm1.Button2Click(Sender: TObject);
var
    strData : string;
    PostData: OleVariant;
    Headers: OleVariant;
    i : integer;
    strXMLReturn : string;
begin
    strData := '<xml></xml>'; // Put your POST data here.
    PostData := VarArrayCreate([0, Length(strData) - 1], varByte);
    for i := 1 to Length(strData) do
        PostData[i-1] := Ord(strData[i]);
    Headers := 'Content-Type: application/x-www-form-urlencoded' + #10#13 +
    'Referer: https://somesite.com/' + #10#13;

    // Now navigate to the URL
    WebBrowser1.Navigate('http://www.SomeWebSite.com/something/api/abc_order?access_key=abc&id=16', EmptyParam, EmptyParam, PostData, Headers);
    while not bReadPage do
        Application.ProcessMessages;

  strXMLReturn:=Document_GetHTML(WebBrowser1.Document);
  Memo1.Lines.Add(strXMLReturn);
  {memo1.lines.LoadFromStream(PostData);}
  {Memo1.Text:=strXMLReturn;}
  {Memo1.Lines.LoadFromStream(TMemoryStream(WebBrowser.Document));}

end;

function TForm1.Document_GetHTML(Document: IDispatch):string;
var
 ms: TStringStream;
begin
 Result := '';
 if Assigned(Document) then
 begin
    ms := TStringStream.Create(Result);
    try
       OleCheck((Document as IPersistStreamInit).Save(TStreamAdapter.Create(ms),False));
       Result := ms.DataString;
    finally
       ms.Free;
    end;
 end;
end;
0
Keith
2/25/2013 5:36:40 PM
embarcadero.delphi.webservices 976 articles. 0 followers. Follow

4 Replies
3351 Views

Similar Articles

[PageSpeed] 30

I got the IDhttp component to work, but I would still be interested in getting this to work. Thanks.

> {quote:title=Keith Shultz wrote:}{quote}
> The webbrowser component is properly sending and receiving. The result that I get is visible within the browser window. It is XML text, and I would like to load this information into a TMemo. I have tried different techniques suggested on the Internet, including the one shown below. However, I either get nothing in the TMemo, or I get:   ÿþ<   
> 
> Any suggestions? (I have tried using the idhttp component, but I am not getting anything in response.) I am using Delphi 5.
> 
> procedure TForm1.Button2Click(Sender: TObject);
> var
>     strData : string;
>     PostData: OleVariant;
>     Headers: OleVariant;
>     i : integer;
>     strXMLReturn : string;
> begin
>     strData := '<xml></xml>'; // Put your POST data here.
>     PostData := VarArrayCreate([0, Length(strData) - 1], varByte);
>     for i := 1 to Length(strData) do
>         PostData[i-1] := Ord(strData[i]);
>     Headers := 'Content-Type: application/x-www-form-urlencoded' + #10#13 +
>     'Referer: https://somesite.com/' + #10#13;
> 
>     // Now navigate to the URL
>     WebBrowser1.Navigate('http://www.SomeWebSite.com/something/api/abc_order?access_key=abc&id=16', EmptyParam, EmptyParam, PostData, Headers);
>     while not bReadPage do
>         Application.ProcessMessages;
> 
>   strXMLReturn:=Document_GetHTML(WebBrowser1.Document);
>   Memo1.Lines.Add(strXMLReturn);
>   {memo1.lines.LoadFromStream(PostData);}
>   {Memo1.Text:=strXMLReturn;}
>   {Memo1.Lines.LoadFromStream(TMemoryStream(WebBrowser.Document));}
> 
> end;
> 
> function TForm1.Document_GetHTML(Document: IDispatch):string;
> var
>  ms: TStringStream;
> begin
>  Result := '';
>  if Assigned(Document) then
>  begin
>     ms := TStringStream.Create(Result);
>     try
>        OleCheck((Document as IPersistStreamInit).Save(TStreamAdapter.Create(ms),False));
>        Result := ms.DataString;
>     finally
>        ms.Free;
>     end;
>  end;
> end;
0
Keith
2/25/2013 8:02:12 PM
Something like this you looking for?

function GetBrowserHtml(const webBrowser: TWebBrowser): String;
var
  strStream: TStringStream;
  adapter: IStream;
  browserStream: IPersistStreamInit;
begin
  strStream := TStringStream.Create('');
  try
    browserStream := webBrowser.Document as IPersistStreamInit;
    adapter := TStreamAdapter.Create(strStream,soReference);
    browserStream.Save(adapter,true);
    result := strStream.DataString;
  finally
  end;
  strStream.Free();
end;
0
steven
2/25/2013 9:00:33 PM
Same (wrong) result: ÿþ<

> {quote:title=steven chesser wrote:}{quote}
> Something like this you looking for?
> 
> function GetBrowserHtml(const webBrowser: TWebBrowser): String;
> var
>   strStream: TStringStream;
>   adapter: IStream;
>   browserStream: IPersistStreamInit;
> begin
>   strStream := TStringStream.Create('');
>   try
>     browserStream := webBrowser.Document as IPersistStreamInit;
>     adapter := TStreamAdapter.Create(strStream,soReference);
>     browserStream.Save(adapter,true);
>     result := strStream.DataString;
>   finally
>   end;
>   strStream.Free();
> end;
0
Keith
2/25/2013 10:48:58 PM
> {quote:title=Keith Shultz wrote:}{quote}
> Same (wrong) result: ÿþ<
> 
> > {quote:title=steven chesser wrote:}{quote}
> > Something like this you looking for?
> > 
> > function GetBrowserHtml(const webBrowser: TWebBrowser): String;
> > var
> >   strStream: TStringStream;
> >   adapter: IStream;
> >   browserStream: IPersistStreamInit;
> > begin
> >   strStream := TStringStream.Create('');
> >   try
> >     browserStream := webBrowser.Document as IPersistStreamInit;
> >     adapter := TStreamAdapter.Create(strStream,soReference);
> >     browserStream.Save(adapter,true);
> >     result := strStream.DataString;
> >   finally
> >   end;
> >   strStream.Free();
> > end;

ah ok.. i pointed my twebbrowser to an XML file on my system and tried the above code and got the same result as you.

 function getxmldata(const webbrowser:twebbrowser):string;
 var
  HTML: IHtmlDocument2;
begin
  HTML := webbrowser.Document as IHTMLDocument2;
  Result := HTML.body.outerText;
end;

I ran this, and it returned the XML data
0
steven
2/27/2013 1:18:59 AM
Reply:

Similar Artilces:

Passing xmlrequest to webservice and getting response from the webservice by serialization in classes.
Hi All,      Iam try to pass the request to the webservice. I was told to send the request in the below format using classes n properties. I can't able to understand how it should be done. Plz help me in this. Can anyone explain it indetail. The code format should be : Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click           Dim objPropertyInfoRQ As PropertyInfoRequest = New PropertyInfoRequest        Dim objPropertyInfoRS As...

How do I get the Text of a Text ....
That may sound confusing, but I need to get the text of a Dynamically created text object. For each row the Text objects text might be somthing different, and when I loop through all the rows, I need to see if any of them are a certain Word. When I used Getitemstring, it doesn't like it. dw_1.Describe( 'text_control.text' ) will give you the .text attribute of a text control in a datawindow. How are you getting different values for the .text attributes on different rows? Using an expression or something? -- Paul Horan[TeamSybase] VCI Springfield, MA www.v...

get text of Response.Write
hi i tried to use an Exif Reader Library. have the sample code as belowvoid ShowImageExif()    {        string filename = MapPath("~/IMG_0230.JPG");        System.Drawing.Bitmap b = new System.Drawing.Bitmap(filename);         Goheer.EXIF.EXIFextractor er = new Goheer.EXIF.EXIFextractor(ref b, "\n");        Response.Write(er); //show all data        Response.Write(er["Date Time"]); //to read the Date Tim...

length or trim ? how can i get textbox.text as text that publichouse to textbox.text as text that public ?
hello friends length or trim ? how can i get textbox.text as text that publichouse to textbox.text as text that public ? second example is ..... textbox1.text is greenhouse.. i want to get green from textbox.text cheer Mark as me if my question or my answer can be helpful for you :) Hi,you can always perform a Trim to a retrieved string to delete the leading and trailing space characters. For your second example where you want to gt a part of the retrieved string you can use the SubString method of the String class.Grz, Kris. Read my blog. Handy Firefox plugins for web developers.Workar...

how to get rid of xmlns attribute from webservice response?
Hi there,I have the webservice methods.. which accepts requests and responds in specified format given by our client..My problem is wen i send the response xmlns attribute is adding automatically in the element tag:<Response_Data xmlns="">    <rslt Success="False"/></Response_Data>how to get rid of this from the reponse tag..Please help!! I believe I answered this in The Other Place, but why do you think you want to get rid of that xmlns?John Saunders | MVP – Connected System Developer Hi john, Sorry for the late reply. As my cl...

getting html code of selected text in webbrowser ?
how to get the htmlcode of the selected text in webbrowser ? Thanks. Edited by: mehmet yalçın on Nov 24, 2008 10:38 AM "mehmet yalçin" <=?Utf-8?Q?mehmet_yal=C3=A7=C4=B1n?=> wrote in message news:47384@forums.codegear.com... > how to get the htmlcode of the selected text in webbrowser ? Thanks. First off, is the web browser embedded in your app, or is it running external? And which browser(s) are you interested in? It makes a difference in how, and if, you can access the browser contents at all. -- Remy Lebeau (TeamB) (Twebbrowser component...

Is there a way to get response size for a webservice call
Hi I am calling a webservice through asp.net ajax client. Once I get the response in the callback function, how can I find out what is the actual size of the response. Is it possible to access the response headers programatically? Thanks Hi ,  I think this is what you are looking for .  http://ajax.asp.net/docs/ClientReference/Sys.Net/WebRequestClass/default.aspxPhani Rajhttp://blogs.msdn.com/PhaniRaj...

Getting error: Invalid response from webservice error
Anyone ever get this message before? Error: Invalid response from webservice:*url*: Invalid Request: Untranslatable Request Tags --> Invalid Request: Untranslatable Request Tags --> Exception from HRESULT: 0x80040613. Line 36: public System.Xml.XmlElement SubmitXml(string Profile, System.Xml.XmlElement Request, System.Xml.XmlElement Filter) Line 37: { Line 38: object[] results = this.Invoke("SubmitXml", new object[]{Profile, Request, Filter}); Line 39: return ((System.Xml.XmlElement)(results[0])); Line 40: } it is erroring on Line 38. T...

Get cookie details from webbrowser on response from server....
Hi    I have a senario like this i am getting a login page on webbrowser control.   i type user-id and password.on sucessfull login server sends the response which has the cookie Id and Cookie value.How can i get those information.   And on which event i will get those details, Because the submit button is a part of the html content that has loaded to webbroswer control. (Like i pass a url webbrowser1.url(http://mail.yahoo.com); i got yahoo mail page in webbrowser control. i typed my userid and password and click submit.In the response i should get the cookie value s...

,text and why is there , begin of text ?? i use Response.Redirect(String.Format("asanat.aspx?TextBox1={0}&TextBox2={1}&TextBox3={2}&TextBox3={3}", Label1.Text, Label2.Text, Label3.Text, Label4.Text))
hello friends ,text and why is there , begin of text ?? i use label4.text="text" Response.Redirect(String.Format("asanat.aspx?TextBox1={0}&TextBox2={1}&TextBox3={2}&TextBox3={3}", Label1.Text, Label2.Text, Label3.Text, Label4.Text)) from masterpage1.master and asanat.aspx connect to masterpage2.master.. below code is in masterpage2.master because label4.text in masterpage2.masterProtected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Request("TextBox3") IsNot Nothing ThenLabel4.Text = Request("TextB...

Delphi 5
I am new to web services.I am trying to consume data from a wcf web service which is written in C#.I have successfully consumed the response from the webservice.But When I try to Parse the response string to a DOM Node using TXmlDomParser it is throwing an error saying *Parser Error*.This is happening only when replace the strings lt and gt with < and > characters.Other wise it is parsing but I am unable to get the node values as response is having lt and gt strings instead of < and > *Here is a piece of code* +cReturn := stResponse.DataString //Response is successful from th...

DOM, how to get text out of text node
Hi all, i am stack on this: i am parsing a dom document, i reach a text node, but i can't get the text out of the text node. Hope some one can help. this is the code: childs is a nsIDOMNodeList. PRUint32 len, i; childs->GetLength( &len ); nsCOMPtr<nsIDOMNode> child; nsEmbedString name; nsEmbedString value; PRUint16 type; for( i = 0; i < len; i++ ) { childs->Item( i, getter_AddRefs( child ) ); child->GetNodeType( &type ); child->GetLocalName( name ); ...

Copy web text fr FF2 PASTE to outlook text mail msg get an attachment not text
I never had this problem with IE. When I copy text from a web page and try to paste it as text into an Outlook2000 TEXT mail message, it instead is rendered into an attachment to the message. I just want to paste the text. Does anyone know why this happens, better yet - how to fix it? Currently I have to past the text into a text editor, and then recopy that into my Outlook mail message. This is getting old fast. Thanks in advance. Sandalls On 2/23/2007 5:01 PM On a whim, Sandalls pounded out on the keyboard > I never had this problem with IE. > > When I co...

How does text gets displayed in composer text field?
Hi, I'm new to TB dev. I stumbled upon this problem while trying to fix bug 309= 708. I am trying to figure out how does a message gets displayed in the com= poser window? I noticed that when I click edit on a mail in my drafts folde= r, the text in the uncompleted mail is displayed in the composer. I want to= do something similar to this. Does anyone know how does TB copy the text from the mail and display it on = the composer window? Is there like a textField.setText() to put the text into the composer's edi= ting text field? In another words, what function should i ca...