Search in sources :

Example 1 with HttpException

use of org.nutz.http.HttpException in project nutz by nutzam.

the class FilePostSender method send.

@Override
public Response send() throws HttpException {
    try {
        String boundary = "------FormBoundary" + R.UU32();
        openConnection();
        setupRequestHeader();
        conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
        setupDoInputOutputFlag();
        Map<String, Object> params = request.getParams();
        if (null != params && params.size() > 0) {
            export(params, getOutputStream(), boundary, request.getEnc());
        }
        return createResponse(getResponseHeader());
    } catch (IOException e) {
        throw new HttpException(request.getUrl().toString(), e);
    }
}
Also used : HttpException(org.nutz.http.HttpException) IOException(java.io.IOException)

Example 2 with HttpException

use of org.nutz.http.HttpException in project nutz by nutzam.

the class GetSender method send.

@Override
public Response send() throws HttpException {
    try {
        openConnection();
        setupRequestHeader();
        return createResponse(getResponseHeader());
    } catch (Exception e) {
        throw new HttpException(request.getUrl().toString(), e);
    }
}
Also used : HttpException(org.nutz.http.HttpException) HttpException(org.nutz.http.HttpException)

Example 3 with HttpException

use of org.nutz.http.HttpException in project nutz by nutzam.

the class PostSender method send.

@Override
public Response send() throws HttpException {
    try {
        openConnection();
        InputStream ins = request.getInputStream();
        setupRequestHeader();
        if (ins != null && request.getHeader() != null && ins instanceof ByteArrayInputStream && this.request.getHeader().get("Content-Length") == null)
            conn.addRequestProperty("Content-Length", "" + ins.available());
        setupDoInputOutputFlag();
        if (null != ins) {
            OutputStream ops = Streams.buff(getOutputStream());
            Streams.write(ops, ins);
            Streams.safeClose(ins);
            Streams.safeFlush(ops);
            Streams.safeClose(ops);
        }
        return createResponse(getResponseHeader());
    } catch (Exception e) {
        throw new HttpException(request.getUrl().toString(), e);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) HttpException(org.nutz.http.HttpException) HttpException(org.nutz.http.HttpException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

HttpException (org.nutz.http.HttpException)3 IOException (java.io.IOException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1