WinHTTPRequest

bhalpinbhalpin Member Posts: 309
Hi.

I'm at my wits end. ](*,)

All I want to do is retrieve a page from the web and strore it in a text var, bigtext var, file, - I really don't care.

This is what I have so far:
// Only var: WinHTTPRequest - Automation - 'Microsoft WinHTTP Services, version 5.1'.WinHttpRequest

IF NOT ISCLEAR(WinHTTPRequest) THEN CLEAR(WinHTTPRequest);
CREATE(WinHTTPRequest);
WinHTTPRequest.Open('GET','http://www.mibuso.com',FALSE);
WinHTTPRequest.Send;

MESSAGE('Status='+FORMAT(WinHTTPRequest.Status()));
MESSAGE('StatusText='+WinHTTPRequest.StatusText());

The Status and StatusText return '200' and 'OK'.

But I have wasted several hours trying to get past this point. I've messed with instreams, outstreams, variants, blobs, - you name it.

Can anyone supply the next few lines?

Thanks' in advance

Answers

  • garakgarak Member Posts: 3,263
    check the RESPONSE methode like:
    Name        DataType    Subtype   Length
    WinHttpReq  Automation  'Microsoft WinHTTP Services, version 5.1'.WinHttpRequest
    IStream   InStream
    URL  Text    250
    
    URL := 'http://www.mibuso.com';
    IF ISCLEAR(WinHttpReq) THEN
      CREATE(WinHttpReq);
    
    WinHttpReq.Open('GET',URL,FALSE);
    WinHttpReq.Send;
    IF NOT WinHttpReq.WaitForResponse() THEN
      ERROR('Timed out');
    
    // Alway's displays '200' and 'OK'
    MESSAGE('Status: '+FORMAT(WinHttpReq.Status())+'\'+
                   'StatusText: '+WinHttpReq.StatusText());
    
    IStream := WinHTTPRequest.ResponseStream;
    
    WHILE NOT IStream.EOS DO BEGIN
      //Here do anything like reading the chars in the Stream
    END;
    


    Also you can search the Forum for WinHTTP

    Regards
    Do you make it right, it works too!
  • bhalpinbhalpin Member Posts: 309
    Thanks! That did it! =D>

    For others, reading this, in his code IStream is an InStream variable. You access the text of the page by doing something like this:
    // InText is a text var
    WHILE NOT IStream.EOS DO BEGIN
      //Here do anything like reading the chars in the Stream
      IStream.READTEXT(InText,128);  // reads 128 chars into var InText
      // Do whatever with InText
    END;
    
  • garakgarak Member Posts: 3,263
    You're welcome
    Do you make it right, it works too!
  • AgemAgem Member Posts: 1
    Hey Guys,

    i have try this in Navision 3.70B and it did'n work :( i've got the message with the following informations:

    This data type is not supported by C / SIDE.
    You have access to data of the following data types:
    VT_VOID, VT_I2, VT_I4, VT_R4, VT_R8, VT_CY, VT_DATE, VT_BSTR and VT_BOOL

    the debugger hold on
    IStream := WinHTTPRequest.ResponseStream;
    

    thanks for some help
  • ara3nara3n Member Posts: 9,256
    tyr XmlDoc.load(WinHTTP.ResponseBody); if it's an xml file. otherwise you'll need to do exe upgrade
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
Sign In or Register to comment.