All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mo.mohttp.impl.FormUrlencodedEntity Maven / Gradle / Ivy

package com.mo.mohttp.impl;


import com.mo.mohttp.constant.ContentType;
import com.mo.mohttp.http.Entity;
import com.mo.mohttp.http.NameValuePair;


import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.util.List;

/**
 * 
 * An entity composed of a list of url-encoded pairs. This is typically useful while sending an HTTP POST request.
 * For example:
 *
 * parameters:
 * a = 1
 * b = 2
 * c = 100
 *
 * FormUrlencodedEntity:
 * a=1&b=2&c=100
 * 
* */ public class FormUrlencodedEntity implements Entity { private Charset charset; private List paramList; public FormUrlencodedEntity(List paramList, Charset encoding){ this.charset = encoding; this.paramList = paramList; } @Override public long getContentLength() { return 0; } @Override public long writeLength() { return 0; } @Override public String getContentType() { return ContentType.FORM_DEFAULT; } @Override public Charset getContentEncoding() { return charset; } @Override public void writeTo(DataOutputStream out) throws IOException { for(int i=0;i0){ out.writeBytes("&"); } out.writeBytes(URLEncoder.encode(pair.getName(),charset.displayName())); out.writeBytes("="); out.writeBytes(URLEncoder.encode(pair.getValue(),charset.displayName())); } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy