I love my well used result = system.net.httpPost(url, params). I insert my API url and dictionary of parameters then decode the beautiful json that gets returned. Now I have to update all our legacy code and this httpClient is not making me happy! So I am getting back a 200 with the new code. The funny thing is it is not populating the $_POST variables on the server. I do not believe it is being redirected because if I put params=payload it populates $_GET. data=payload populates nothing.
The corporate overlords recently pwned my machine so now I can't put whatever I want on here. Could an old PHP setup be the problem? our server is only 5.3.3
Educated guess, try setting an explicit HTTP version of 1.1 when using httpClient.
Untested (obviously) adjusted code with no other significant changes:
def postShowSafetyAssets(self):
window = system.vision.getWindow('Safety')
lbl = window.rootContainer.getComponent('lblCurrentAction')
buttons = [window.rootContainer.getComponent("btnRequest" + str(i)) for i in range(1,25)]
posttags = ["[default]HttpRequest/Weld/urlsafety", "[default]HttpRequest/key"]
postvals = system.tag.readBlocking(posttags)
data = {"k":postvals[1].value, "w":"AB", "l":"ABB Welder", "t":"welder"}
result = system.net.httpClient(version="HTTP_1_1").post(postvals[0].value, data)
if result.good:
if result.json['status']=="OK":
if "items" in result.json:
message = result.json["subtitle"]
items = result.json["items"]
for item, button in zip(items, buttons):
button.text = item["name"]
else:
pass
lbl.text = message
If this works you really want to instantiate your http client in a project library script somewhere so you're not creating a whole new http client every time you click a button.
As an aside, there's zero reason for urgency in migrating away from httpPost in the first place.
When we deprecate scripting functions, we hide them to discourage new code from using them, but with extremely rare exceptions, we keep them working, with the same signature, ~forever.
Hey Paul, I thought this was "fixed" recently, in that we didn't need to worry about creating an http client within a module variable anymore, as you do it under the hood? Or did I misunderstand?
The change in 8.3 is that system.net.httpClient is auto-magically both an instance of the HTTP client (created with all default settings) and the factory function for new instances.
So you if you were previously running system.net.httpClient().doSomething(), you can swap that to system.net.httpClient.doSomething() and it'll work exactly the same, but is guaranteed to re-use the same lazily created HTTP client instance.
However, if you have to customize the creation of the http client in any way, the same don't-create-a-million-instances rules apply.