Highlighted
Absent Member.
Absent Member.
594 views

Tutorial or example for calling a URL and processing the response

I was wondering if there is a tutorial or example for calling a URL and manipulating the response.

0 Likes
6 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Tutorial or example for calling a URL and processing the response

Hi,

Can you provide a bit more detail?
What do you mean exactly by calling a URL?
Are you trying to call a Web Service at a particular URL?
What type of Web Service?
What type of code is your client program, native, managed .NET, managed JVM?

Thanks
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Tutorial or example for calling a URL and processing the response

I wish to call an internal website by URL (http://). This site constructs a report, and sends back a location where the report is created. So, the program would have to call a link (http://) and send the request. Then would receive the http response, and manipulate the text sent back.

In C# it is done by instantiating a web browser object, setting the url, and using the methods to send the request and receive the response.
0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Tutorial or example for calling a URL and processing the response

Are you using managed .NET COBOL?
If you are then you should be able to perform this function using the same class and methods that you do in C#.
If you post the example C# code I will convert it to the equivalent COBOL for you...
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Tutorial or example for calling a URL and processing the response

I ran into issues at work, and I was unable to create this. I will get to it ASAP.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Tutorial or example for calling a URL and processing the response

I used HttpWebRequest instead, but this returns a value from Google's main site. Console app.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;

namespace WebBrowserConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            var webAddr = "https://www.google.com";

            var httpWebRequest = (HttpWebRequest) WebRequest.Create(webAddr);

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

            httpWebRequest.Method = "GET";

            var httpResponse = (HttpWebResponse) httpWebRequest.GetResponse();

            using(var streamReader = new StreamReader(httpResponse.GetResponseStream()))

            {

                var result = streamReader.ReadToEnd();

                Console.WriteLine(result);

            }
        }
    }
}

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Tutorial or example for calling a URL and processing the response

The Visual COBOL equivalent to this using a program instead of a class would be (you could use either)

 

      $set ilusing"System"
      $set ilusing"System.Collections.Generic"
      $set ilusing"System.IO"
      $set ilusing"System.Net"
      $set ilusing"System.Text"
       program-id. Program1 as "WebBrowserConsoleApplication.Program1".
       procedure division.
           declare webAddr = "https://www.google.com"
           declare httpWebRequest = type WebRequest::Create(webAddr) as type HttpWebRequest

           set httpWebRequest::ContentType = "application/x-www-form-urlencoded"

           set httpWebRequest::Method = "GET"

           declare httpResponse = httpWebRequest::GetResponse as type HttpWebResponse

           perform using streamReader as type StreamReader = new type StreamReader(httpResponse::GetResponseStream)
               declare result = streamReader::ReadToEnd
               invoke type Console::WriteLine(result)
           end-perform
            
           goback.
           
       end program Program1.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.