Code example for HttpURLConnection

Methods: getOutputStream, setConnectTimeout, setDoOutput, setReadTimeout, setRequestMethod

0
	public OutputStream openOutputStream() throws IOException {
		if(this.output != null) {
			throw new IOException("already opened");
		} 
		connect(); 
		this.connection.setDoOutput(true);
		this.output = this.connection.getOutputStream();
		return this.output;
	} 
	 
	 
	//only in setup state 
	public void setRequestMethod(String requestMethod) throws IOException {
		if (this.state == STATE_SETUP) {
			if (requestMethod.equals(GET)) {
				this.requestMethod = requestMethod;
			} else if (requestMethod.equals(POST)) {
				this.requestMethod = requestMethod;
			} else { 
				throw new IllegalArgumentException("illegal request method " + requestMethod);
			}