system.net.httpClient() causes java.io.IOException while system.net.httpGet() works fine

I am currently able to pull in data from the JIRA REST API using system.net.httpGet(), but when I try the same request with system.net.httpClient().get() I receive a java.io.IOException GOAWAY.

# Working request
url = "URL"
headers = {"Accept": "application/json"}
contentType = "application/json"
username = "USER"
password = “API_KEY”
response = system.net.httpGet(url = url, contentType = contentType, headerValues = headers, username = username, password = password)
# Broken request
url = "URL"
headers = {"Accept": "application/json"}
username = "USER"
password = “API_KEY”
response = system.net.httpClient().get(url = url, headers = headers, username = username, password = password)

I have checked for header differences between the two calls and found none. I also tried changing the redirect_policy which led to no improvement. Is there a difference with how the Java 11 HttpClient makes the connection with the API server that differs from the old system.net.httpGet() that might lead to this issue?

Note: This is on 8.0.17.

httpClient is using HTTP/2, which the target server is apparently not accepting and apparently not negotiating correctly. Unfortunately, the solution (telling HttpClient to only use HTTP/1) is not currently viable due to a bug:

Until that bug is fixed, you'll likely have to keep using httpGet.

2 Likes

Thank you for the explanation - I’ll be looking out for an update in the future. In the meantime, is there a compatible library I could use to execute a “multipart/form-data” POST with? It’s the reason why I wanted to try using system.net.httpClient() in the first place. I don’t believe system.net.httpPost() will work.

Actually, httpClient doesn't do you any favors with multipart/form-data at present either (:frowning:). I've seen customers use requests in Ignition directly; you can access pip to install it more easily using the method outlined here:

1 Like

Hi @PGriffith is that [BUG-16787] still not fixed?
I’m on 8.1.17 and trying to use httpClient.post and i think i am running into the same problem in this thread.

This works:

resp = system.net.httpPost(url=postUrl, contentType="application/json", postData=payload, username="REDACTED", password="REDACTED", throwOnError=False)

This doesn’t:

client = system.net.httpClient()
response = client.post(url=postUrl, data=payload, username="REDACTED", password="REDACTED")

I get the following error:

com.inductiveautomation.ignition.common.script.JythonExecException
Traceback (most recent call last):
  File "<function:runAction>", line 81, in runAction
  File "<function:runAction>", line 67, in testSendMsg3
java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: java.io.IOException: Can't get stream 1: java.io.EOFException: EOF reached while reading

	caused by org.python.core.PyException
Traceback (most recent call last):
  File "<function:runAction>", line 81, in runAction
  File "<function:runAction>", line 67, in testSendMsg3
java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: java.io.IOException: Can't get stream 1: java.io.EOFException: EOF reached while reading

	caused by ExecutionException: java.io.IOException: Can't get stream 1: java.io.EOFException: EOF reached while reading
	caused by IOException: Can't get stream 1: java.io.EOFException: EOF reached while reading
	caused by EOFException: EOF reached while reading

Ignition v8.1.13 (b2021122109)
Java: Azul Systems, Inc. 11.0.13

Your error message says you’re on 8.1.13.

Since 8.1.16 there is a version parameter you can set when using system.net.httpClient: system.net.httpClient - Ignition User Manual 8.1 - Ignition Documentation (inductiveautomation.com)

Thanks Kevin,

My bad, i forgot what gateway i was testing this on. There are 5 gateways on this project and i updated all of them (except this one) to 8.1.17 recently.
I’ll try update it and see how we go with that new version option.
Cheers

Edit: Yep that worked fine forcing version to “HTTP_1_1”. Cheers