• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hazendaz / httpunit / 755

14 Feb 2026 07:14PM UTC coverage: 80.526%. Remained the same
755

push

github

hazendaz
[ci] Fix badge

3213 of 4105 branches covered (78.27%)

Branch coverage included in aggregate %.

8245 of 10124 relevant lines covered (81.44%)

0.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

81.82
/src/main/java/com/meterware/httpunit/PostMethodWebRequest.java
1
/*
2
 * SPDX-License-Identifier: MIT
3
 * See LICENSE file for details.
4
 *
5
 * Copyright 2000-2026 Russell Gold
6
 * Copyright 2021-2000 hazendaz
7
 */
8
package com.meterware.httpunit;
9

10
import com.meterware.httpunit.protocol.MessageBody;
11
import com.meterware.httpunit.protocol.URLEncodedString;
12

13
import java.io.IOException;
14
import java.io.InputStream;
15
import java.net.URL;
16

17
/**
18
 * An HTTP request using the POST method.
19
 **/
20
public class PostMethodWebRequest extends MessageBodyWebRequest {
21

22
    /**
23
     * Constructs a web request using a specific absolute url string.
24
     *
25
     * @param urlString
26
     *            the url string
27
     */
28
    public PostMethodWebRequest(String urlString) {
29
        this(urlString, false);
1✔
30
    }
1✔
31

32
    /**
33
     * Constructs a web request using a specific absolute url string, with optional mime encoding.
34
     *
35
     * @param urlString
36
     *            the url string
37
     * @param mimeEncoded
38
     *            the mime encoded
39
     */
40
    public PostMethodWebRequest(String urlString, boolean mimeEncoded) {
41
        super(urlString, mimeEncoded);
1✔
42
    }
1✔
43

44
    /**
45
     * Constructs a web request with a specific target.
46
     *
47
     * @param urlBase
48
     *            the url base
49
     * @param urlString
50
     *            the url string
51
     * @param target
52
     *            the target
53
     */
54
    public PostMethodWebRequest(URL urlBase, String urlString, String target) {
55
        this(urlBase, urlString, target, false);
×
56
    }
×
57

58
    /**
59
     * Constructs a web request with a specific target, with optional mime encoding.
60
     *
61
     * @param urlBase
62
     *            the url base
63
     * @param urlString
64
     *            the url string
65
     * @param target
66
     *            the target
67
     * @param mimeEncoded
68
     *            the mime encoded
69
     */
70
    public PostMethodWebRequest(URL urlBase, String urlString, String target, boolean mimeEncoded) {
71
        super(urlBase, urlString, target, mimeEncoded);
×
72
    }
×
73

74
    /**
75
     * Constructs a web request using a specific absolute url string and input stream.
76
     *
77
     * @param urlString
78
     *            the URL to which the request should be issued
79
     * @param source
80
     *            an input stream which will provide the body of this request
81
     * @param contentType
82
     *            the MIME content type of the body, including any character set
83
     **/
84
    public PostMethodWebRequest(String urlString, InputStream source, String contentType) {
85
        super(urlString, false);
1✔
86
        _body = new InputStreamMessageBody(source, contentType);
1✔
87
    }
1✔
88

89
    /**
90
     * Returns the HTTP method defined for this request.
91
     **/
92
    @Override
93
    public String getMethod() {
94
        return "POST";
1✔
95
    }
96

97
    /**
98
     * Returns the query string defined for this request.
99
     **/
100
    @Override
101
    public String getQueryString() {
102
        try {
103
            URLEncodedString encoder = new URLEncodedString();
1✔
104
            getParameterHolder().recordPredefinedParameters(encoder);
1✔
105
            return encoder.getString();
1✔
106
        } catch (IOException e) {
×
107
            throw new RuntimeException("Programming error: " + e); // should never happen
×
108
        }
109
    }
110

111
    /**
112
     * Returns true if selectFile may be called with this parameter.
113
     */
114
    @Override
115
    protected boolean maySelectFile(String parameterName) {
116
        return isMimeEncoded() && isFileParameter(parameterName);
1✔
117
    }
118

119
    // ----------------------------- MessageBodyWebRequest methods ---------------------------
120

121
    @Override
122
    protected MessageBody getMessageBody() {
123
        if (_body == null) {
1✔
124
            _body = MessageBody.createPostMethodMessageBody(isMimeEncoded(), getCharacterSet());
1✔
125
        }
126
        return _body;
1✔
127
    }
128

129
    // ----------------------------------- package members -----------------------------------
130

131
    /**
132
     * Constructs a web request for a form submitted by clicking a button.
133
     *
134
     * @param sourceForm
135
     *            the source form
136
     * @param button
137
     *            the button
138
     * @param x
139
     *            the x
140
     * @param y
141
     *            the y
142
     */
143
    PostMethodWebRequest(WebForm sourceForm, SubmitButton button, int x, int y) {
144
        this(sourceForm, sourceForm, button, x, y);
1✔
145
    }
1✔
146

147
    /**
148
     * Instantiates a new post method web request.
149
     *
150
     * @param sourceForm
151
     *            the source form
152
     * @param parameterHolder
153
     *            the parameter holder
154
     * @param button
155
     *            the button
156
     * @param x
157
     *            the x
158
     * @param y
159
     *            the y
160
     */
161
    PostMethodWebRequest(WebForm sourceForm, ParameterHolder parameterHolder, SubmitButton button, int x, int y) {
162
        super(sourceForm, parameterHolder, button, x, y);
1✔
163
    }
1✔
164

165
    /**
166
     * Constructs a web request for a form submitted via a script.
167
     *
168
     * @param sourceForm
169
     *            the source form
170
     */
171
    PostMethodWebRequest(WebForm sourceForm) {
172
        super(sourceForm);
1✔
173
    }
1✔
174

175
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc