Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Java/Foxpro HTTP Authentication
Message
From
06/05/2008 14:11:13
Jay Johengen
Altamahaw-Ossipee, North Carolina, United States
 
 
To
All
General information
Forum:
Java
Category:
Other
Title:
Java/Foxpro HTTP Authentication
Miscellaneous
Thread ID:
01315392
Message ID:
01315392
Views:
108
UPDATE: Forget everything below; the bright and well-paid Software Engineer originally told me to use "Authentication" instead of the "authorization" in the SetRequestHeader. It works now.


Here is part of some Foxpro code that I'm using to try and do Basic Authentication.
* Create XMLHttp Object
lxmlObj = CreateObject("Microsoft.XMLHTTP")

* Set Header
*lxmlObj.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")

* Base64 Encoding
cEncoded = STRCONV(cBuffer,13)
* cDecoded = STRCONV(cEncoded,14)

* Define Authentication String
cAuthenticate = "Basic " + cEncoded

* Open POST
lxmlObj.Open("POST", lcWSDL, .F., cAuthenticate)

* Set Header
lxmlObj.SetRequestHeader("Authentication", cAuthenticate)

* Send
lxmlObj.Send()

* Response
lcResponse = lxmlObj.ResponseText
Below is Java code that was given to me that supposedly does HTTP basic authentication. I'm trying to do the same thing using Foxpro and the Microsoft.XMLHTTP object. Mine doesn't work. The guy I got the Java code from says his does. Anyone know what I need to do to mine to make the Foxpro code above work?

Also, how can I run the Java code to test it?
//import jdk classes

import java.io.PrintWriter;

import java.io.BufferedReader;

import java.io.InputStreamReader;

import java.net.HttpURLConnection;

import java.security.Security;

 

import com.mckesson.common.security.Base64;

 

 

public class HttpBasicAuth

{

                static String protocalHandler = "com.sun.net.ssl.internal.www.protocol";

                static String securityProvider = "com.sun.net.ssl.internal.ssl.Provider";

                static String id = "userid";

                static String password = "password";

                static String request = "test message";
                public static void main(String args[])

                {

                                String strUrl = "https://www.ftc.gov";

                                System.setProperty("java.protocol.handler.pkgs", protocalHandler);

                                System.out.println("\nStarting test...");

                                //setup the JSSE handler for the connection

                                Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());

                                try

                                {

                                                String authString = id + ":" + password;

                                                String encoding = Base64.encode(authString.getBytes());

                                                System.out.println("authorization unencoded= " + 
                                                          authString + "  encoded = " + encoding +"\n\n");

                                                //setup the HTTP connection

                                                java.net.URL oURL = new java.net.URL(strUrl);

                                                HttpURLConnection oUC (HttpURLConnection)oURL.openConnection();

                                                //setup the auth header

                                                oUC.setRequestProperty("authorization", "Basic: " + encoding);

                                                oUC.setDoInput(true);

                                                oUC.setDoOutput(true);

                                                oUC.connect();

                                                PrintWriter pw = new PrintWriter(oUC.getOutputStream());

                                                pw.print(request);

                                                pw.close();

                                                //grab the response

                                                BufferedReader oBR = new BufferedReader(new 
                                                     InputStreamReader(oUC.getInputStream()));

                                                String oStr = null;

                                                //display the response to STDOUT

                                                while((oStr = oBR.readLine()) != null)

                                                {

                                                                System.out.println(oStr);

                                                }

                                }

                                catch(Exception oExc)

                                {

                                                System.out.println(oExc);

                                }

                                System.out.println("\n\n");

                }

} 
Reply
Map
View

Click here to load this message in the networking platform