Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP call with header options #321

Open
AmitMitr opened this issue Jun 3, 2022 · 0 comments
Open

HTTP call with header options #321

AmitMitr opened this issue Jun 3, 2022 · 0 comments

Comments

@AmitMitr
Copy link

AmitMitr commented Jun 3, 2022

Hello,

[UE 4.27.2]

Trying to use the example HelloRest to call my API.

The following works.

function main() {
let actor = new TextRenderActor(GWorld,{X:100,Z:100},{Yaw:180})
actor.TextRender.SetHorizontalAlignment('EHTA_Center')
actor.TextRender.SetText('Hello Resting 3000')
let result = "";
let request = require('request')

let url = "https://api.ipify.org/?format=json"

request("GET",url ,result).then((result) => {
console.log('This is the result : ', JSON.stringify(result))
actor.TextRender.SetText(JSON.stringify(result))
}).catch((error) => {
console.log('This is the Error : ', JSON.stringify(error))
actor.TextRender.SetText(error)
})

}

And I get the Set Text as the IP.

However when my URL is a bit more trickier in the above function, as in

let url = "http://10.yy.XX.152:50000/sap/opu/odata/sap/ZGW3407_01_STOCK_SRV_02/ZmatstockSet(matnr='T3407-3',werks='1710')?$format=json";

and the server calls for authentication, so I got

var options = {
url: url,
method: 'GET', // Don't forget this line
headers: {
"DataServiceVersion": "2.0" ,
"Accept": "application/json" ,
"Content-Type": "application/json",
"Apikey":"BgBF6Dn2vuWpKjY4YxWfU8sjmfzldTdC",
"X-Requested-With": "X"
},
form: {
'username' : 'User',
'password' : 'password',
}
};

And then I call the request as follows

request(options ,result).then((result) => {
console.log('This is the result : ', JSON.stringify(result))
actor.TextRender.SetText(JSON.stringify(result))
}).catch((error) => {
console.log('This is the Error : ', JSON.stringify(error))
actor.TextRender.SetText(error)
})

I get Error Invalid JSON.

However, I can confirm that my response is correct when the above is called in the browser.

as follows :

{
"d": {
"__metadata": {
"id": "http://10.79.13.152:50000/sap/opu/odata/sap/ZGW3407_01_STOCK_SRV_02/ZmatstockSet(matnr='T3407-3',werks='1710')",
"uri": "http://10.79.13.152:50000/sap/opu/odata/sap/ZGW3407_01_STOCK_SRV_02/ZmatstockSet(matnr='T3407-3',werks='1710')",
"type": "ZGW3407_01_STOCK_SRV_02.Zmatstock"
},
"matnr": "T3407-3",
"werks": "1710",
"UNRESTRICTED_STCK": "7.000 "
}
}

Also, I am able to call the above using an xhr. open('GET' , URL) with set header options.

Not sure where I am going wrong in unreal.js.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant