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.

  • 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
  • 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.
  • 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...
  • I ran into issues at work, and I was unable to create this. I will get to it ASAP.
  • 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);

                }
            }
        }
    }

  • 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.