paramcall.java
来自「Vodafone betavine java api source code, 」· Java 代码 · 共 60 行
JAVA
60 行
package com.bv.api;import java.io.BufferedReader;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStreamReader;import java.net.HttpURLConnection;import java.net.MalformedURLException;import java.net.URL;import java.util.Properties;import sun.misc.BASE64Encoder;/** * An APICall subtype that pases data to the server as parameters in the URL. * @author C. Oattes */public abstract class ParamCall extends APICall { protected ParamCall() { super(); } protected String connect(String uaid, String serverURL) throws ParamNotPresentException, InvalidParameterException, MalformedURLException, IOException { HttpURLConnection connection; BufferedReader responseReader; URL connectionURL = null; checkParams(uaid); connectionURL = constructURL(uaid, serverURL); connection = (HttpURLConnection) connectionURL.openConnection(); String username = ""; String password = ""; Properties values = new Properties(); try { FileInputStream is = new FileInputStream("values.properties"); values.load(is); username = values.getProperty("username"); password = values.getProperty("password"); String encoding = new BASE64Encoder().encode((username + ":" + password).getBytes()); connection.setRequestProperty ("Authorization", "Basic " + encoding); } catch(IOException ioe) { //Ignore if values.properties not present } connection.setConnectTimeout(5000); connection.connect(); responseReader = new BufferedReader(new InputStreamReader(connection.getInputStream())); //Read the response from the server - should be only 1 line String serverResponse = ""; while(responseReader.ready()) { serverResponse += responseReader.readLine() + "\n" ; } connection.disconnect(); System.out.println("Server response: " + serverResponse); return serverResponse; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?