Signing In to WebFOCUS

In this section:

This section provides code examples that demonstrate how to sign in to WebFOCUS.


Top of page

x
Visual Basic .NET Example
Imports System.Net
Imports System.IO
Imports System.Text
Dim cookies As New CookieContainer
Dim webStream As Stream
Dim webResponse As String = ""
Dim request As HttpWebRequest
Dim response As HttpWebResponse
Dim postData As String
request = WebRequest.Create("http://localhost:8080/ibi_apps/rs/ibfs")
request.Method = "POST"
postData = "IBIRS_action=signOn&IBIRS_userName=admin&IBIRS_password=admin"
request.CookieContainer = cookies
Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)
request.ContentType = "application/x-www-form-urlencoded"
request.ContentLength = byteArray.Length
Dim dataStream As Stream = request.GetRequestStream()
dataStream.Write(byteArray, 0, byteArray.Length)
dataStream.Close()
response = request.GetResponse()
webStream = response.GetResponseStream()
Dim webStreamReader As New StreamReader(webStream)
While webStreamReader.Peek >= 0
        webResponse = webStreamReader.ReadToEnd()
End While

Top of page

x
Java Example
import java.awt.Frame;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.apache.commons.httpclient.*; 
import org.apache.commons.httpclient.methods.*;
String request = "http://localhost:8080/ibi_apps/rs/ibfs";
HttpClient client = new HttpClient();
PostMethod method = new PostMethod(request);
			
method.addParameter("IBIRS_action","signOn");
method.addParameter("IBIRS_userName","admin");
method.addParameter("IBIRS_password","admin");
		    
int statusCode = client.executeMethod(method);
Header[] cookies = null;
InputStream rstream = null;
		    
rstream = method.getResponseBodyAsStream();
cookies = method.getResponseHeaders("Set-Cookie");
		    
BufferedReader br = new BufferedReader(new InputStreamReader(rstream));
String line;
while ((line = br.readLine()) != null) {
	System.out.println(line);
}
br.close();

Top of page

x
HTML and jQuery Example
<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="utf-8" />
    <script type="text/javascript" src="http://code.jquery.com/jquery-3.1.0.js"> </script>
    <script type='text/javascript' src="http://cdnjs.cloudflare.com/ajax/libs/jquery-ajaxtransport-xdomainrequest/1.0.1/
jquery.xdomainrequest.min.js"></script>
    
    <script type="text/javascript">
        var csrf_name;
        var csrf_value;
        $(document).ready(function (IBIRS_action, IBIRS_userName, IBIRS_password) {
            var contentType = "application/x-www-form-urlencoded; charset=utf-8";
            if (window.XDomainRequest)
                contentType = "text/plain";
            var divToBeWorkedOn = "#AjaxPlaceHolder";
            var webMethod = "http://machine:port/ibi_apps/rs/ibfs";
            var IBIRS_action = "signOn";
            var IBIRS_userName = "admin";
            var IBIRS_password = "admin";
            var parameters = 'IBIRS_action=' + IBIRS_action + '&IBIRS_userName=' + IBIRS_userName + '&IBIRS_password=' + IBIRS_password;
            $.ajax({
                type: "POST",
                url: webMethod,
                data: parameters,
                dataType: "xml",
                contentType: contentType,
                success: alert("success"),
                complete: function(xhr,status) {
                    alert(xhr.responseText);
                    alert(xhr.getAllResponseHeaders());
                },
                error:function(jqXHR,textStatus,errorThrown)
                  {
                    alert("You can not send Cross Domain AJAX requests: " + errorThrown);
                  }
            })
        });
    </script>
</head>
<body>
    <div id="AjaxPlaceHolder">
        <div align="center" class="loader"><img src="logo_webfocus.png" id="load" width="140" height="60" align="middle" /></div>
    </div>
    
    <div class="clear"></div>
</body>
</html>

Information Builders