Forum Discussion
Hi sachin
If you are expecting JSON, have you tried using (vary the HTTP request as appropriate for your need)
<#assign resp = http.client.request("https", "api.test.com", "/context/path").body("param1=val1", "application/x-www-form-urlencoded").json().post() /> <#if resp.hasError> Error! <#else> <#assign jsonResp = resp.content > ${resp.content} </#if>
Thanks,
Thanks PaoloT
I tried the solution but it did not helped. I am getting freemarker error. Below is the error.
{ "error":"
FreeMarker template error:
Method public final lithium.coreapi.webui.template.models.HttpClientRequestTemplateModel lithium.coreapi.webui.template.models.HttpClientRequestTemplateModel.body(java.lang.String,java.lang.String) throws freemarker.template.TemplateModelException takes exactly 2 arguments, 1 was given.
The failing instruction (FTL stack trace):
----------
==> #assign resp = http.client.request("h... [in template "parsing_poc_remove_later.ftl" at line 1, column 1]
----------
Java stack trace (for programmers):
----------
freemarker.template.TemplateModelException: [... Exception message was already printed; see it above ...]
at freemarker.ext.beans.SimpleMemberModel.unwrapArguments(SimpleMemberModel.java:96)
at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:107)
at freemarker.core.MethodCall._eval(MethodCall.java:98)
at freemarker.core.Expression.eval(Expression.java:111)
at freemarker.core.Dot._eval(Dot.java:74)
at freemarker.core.Expression.eval(Expression.java:111)
Thanks,
Sachin
- PaoloT10 years agoLithium Alumni (Retired)
Hi sachin
you need to access the actual values from a real response - the above was just mock code which you need to adapt.
Try this for a working example - remember to whitelist ip.jsontest.com in the Admin settings.
<#assign resp = http.client.request("http", "ip.jsontest.com", "/").json().get() /> <#if resp.hasError> Error! <#else> <#assign jsonResp = resp.content > ${jsonResp.ip} </#if>
Hope it helps
Related Content
- 29 days ago
- 10 years ago
- 8 months ago