Access 9588 SMS gateway (HTTP protocol), 9588's IIS SMS service URL requires authentication, URL used in the program: http: // username: password@000.000.000.000/smbphttpagent/
Access Java code:
URL URL = New URL (buf.tostring ()); system.out.println ("****" buf.tostring ()); httpurlconnection conn = (httpurlConnection) URL.OpenConnection (); string password = "User : password; BASE64Encoder base = new BASE64Encoder (); String encodedPassword = base.encode (password.getBytes ()); conn.setRequestProperty ( "Authorization", "Basic" encodedPassword); conn.setRequestMethod ( "GET"); BufferedReader IN = New buffreradre (New InputStreamReader ())); while (in.readline ()! = null) {out.println (In.Readline ()); bool = true;}
Asp access codes function SendMessage (mobile, strMessage) Dim str, url, postmsg url = "http://000.000.000.00/SmbpHttpAgent/Sxxxxxxx Set objHTTP = Server.CreateObject (" MSXML2.XMLHTTP ") Set xmlDOC = Server.CreateObject ("Msxml.domdocument")
'Setting parameters and its value strrequest = url1objhttp.open "post", postmsg, false, "access account", "access password" set this content-type is important objhttp.setRequestHeader "Content-Type", "Application / x-www-form-urlencoded "objHTTP.Send (strRequest) bOK = xmlDOC.load (objHTTP.responseXML) 'state value to see if objHTTP.Status = 200 then xmlStr = xmlDOC.xmlResponse.Write xmlStrelseResponse.Write objHTTP.Status &"
"response.write objhttp.statustextend ifend functionjohn zukowski
Abstract In the previous TIP, Java TIP 46 describes how to use Java programs to access password protected URLs, through the new Authenticator class of Java 1.2. What should I do if you or your user go to Java 1.1? Basically, there is no Java 1.2, you will lose the benefits of Authenticator. But don't be disappointed! This article will display the Java 1.1 small sector and application. If you need to enter the user name and password, R access needs to enter the URLS of the user name and password. (1250 words) Thank David Wallace Croft, he tracks and fix it.
A bug of the original version of the Base64Converter class,?
The source code of the modified class is listed in this essay.
In the previous skill, we introduced the following scenarios: You use your favorite browser to surf online and encountered an URL requires authorization of the agent or HTTP server. A standard dialog box appears on the screen, you must enter your user name and password in it to access this site. For more clear, the dialog on the screen is shown below.
In the Java program, you will find a question: When you try to read and update information related to the URL from InputStream, a FileNotFoundException will thrown.
Starting from Java 1.2, you can use the Authenticator class, as mentioned above, in Java TIP 46 you have learned. However, in the earlier versions of Java 1.2, the URLs accessed before trying to read the data from the URL, whether the accessed URL is properly protected. If the URL is a password protected, you must manually confirm the password protection response of each URL, and then access the required content. The password protection response occurs in the form of authorization requirements attribute. This property is associated with URLConnection and? Br /> URL. Once the authorization requirements are satisfied, the above information is accessible when reaching a URL.
The authorization character has the following form "Authorization: Basic User Name: Password," where the basic authorization field is encoded in base64 format. (Description of the encoding format can be obtained in RFC 1113. A RFC is a "Requost for Comment" document, basically described some Internet standard, in this case, # 1113 describes the message encryption and authorization program, see the following Resources) For encoding, you can use the Base64Encoder class in Sun.misc Package, or create your own class. ?
In order to establish this access, simply confirm that the URL's UrlConnection has an "authorization" requirement attribute. The following steps describe how to do it.
Step 1: Create a URL
URL URL = New URL (URLString);
Step 2: Get the user name and password for SPECIFICURL
Step 3: Place them in String and use the colon: "Separate
String Userpassword = theusername ":" thepassword;
Step 4: Code the string
String encoding = new sun.misc.base64encoder (). Encode (userpassword.getbytes);
Step 5: Create a URLConnection via URL
UrlConnection uc = url.openconnection ();
Step 6: Set the "Authorization" requirements for the URLConnection
Uc.SetRequestProperty ("Authorization", "Basic" encoding;