I have a working Python code to send simple post requests which is as follow:
def PythonPostRequest():
data = {'appReceiptNum':'LIN2190351771'}
response = requests.post('https://egov.uscis.gov/casestatus/mycasestatus.do', data=data)
print(response.text)
if __name__ == '__main__':
PythonPostRequest()
I am intending on sending thousands upon thousands of such requests, so I figured it would make sense for me to translate that into Java to be able to easily send concurrent requests.
Here is my Java code:
private static void JavaHTTPClient() throws IOException, InterruptedException{
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://egov.uscis.gov/casestatus/mycasestatus.do"))
.POST(HttpRequest.BodyPublishers.ofString("{\"appReceiptNum\":\"LIN2190351771\"}"))
.build();
HttpResponse<String> res = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(res.body());
}
public static void main(String[] args) throws IOException, InterruptedException {
JavaHTTPClient();
}
But the response I get back from it seems to completely ignore the body of the post request. What am I missing here?
Thanks
Edit:
The response we get from the request is pretty long, but here are the important parts:
Python response body:
<script src="/casestatus/scripts/mycasestatus.js;jsessionid=C4E2922DFBA6E55C8461FE64C269A327" type="text/javascript"></script>
<script type="text/javascript">
var appReceiptNum = "LIN2190351771";
var pageTitle = 'Case Status';
var receiptNumberHelperText = '<p>The receipt number is a unique 13-character identifier that USCIS provides for each application or petition it receives. The agency uses it to identify and track its cases.<br/><br/>The receipt number consists of three letters-for example, EAC, WAC, LIN, SRC, NBC, MSC or IOE-and 10 numbers. You can find it on notices of action USCIS has sent you.<br/><br/>Omit dashes ("-") when entering a receipt number. However, you can include all other characters, including asterisks ("*"), if they are listed on your notice as part of the receipt number.</p>';
var receiptNumberHelp = 'Receipt Number Help';
</script>
as well as
<div class="rows text-center">
<h1>Case Was Updated To Show Fingerprints Were Taken</h1>
<p>As of May 24, 2021, fingerprints relating to your Form I-601A, Application for Provisional Unlawful Presence Waiver, Receipt Number LIN2190351771, have been applied to your case. If you move, go to <a href="https://egov.uscis.gov/coa/displayCOAForm.do" target="_blank">www.uscis.gov/addresschange</a> to give us your new mailing address.</p>
</div>
And here is what my Java code returns:
<script src="/casestatus/scripts/mycasestatus.js;jsessionid=EF895D0B2C867A8D243949A7AF6AFAB8" type="text/javascript"></script>
<script type="text/javascript">
var appReceiptNum = "";
var pageTitle = 'Case Status';
var receiptNumberHelperText = '<p>The receipt number is a unique 13-character identifier that USCIS provides for each application or petition it receives. The agency uses it to identify and track its cases.<br/><br/>The receipt number consists of three letters-for example, EAC, WAC, LIN, SRC, NBC, MSC or IOE-and 10 numbers. You can find it on notices of action USCIS has sent you.<br/><br/>Omit dashes ("-") when entering a receipt number. However, you can include all other characters, including asterisks ("*"), if they are listed on your notice as part of the receipt number.</p>';
var receiptNumberHelp = 'Receipt Number Help';
</script>
and
<div class="rows text-center">
<h1></h1>
<p></p>
</div>
The Java response we get is what we get from the Python request if we ommit the request body.