question

Shuo C2 avatar image
0 Likes"
Shuo C2 asked Shuo C2 commented

Http.Response sendAndWait() response.status code returns 0

I've been trying out the Http API in FlexSim 2021 with no success. At first I thought the issue was the API I was trying to hit, but I was able to hit it successfully in Powershell. I also tried hitting google with no success.

Http.Request request;
request.host = "https://www.google.com";
request.method = Http.Method.Get;
Http.Response response = request.sendAndWait();
print(response.value);
print(response.statusCode);

The response I get in the output console is

0

Which I assume is empty string followed by a 0 status code, which isn't a valid Http response status.

Has anybody encountered this before?

FlexSim 21.0.0
flexsim 21.0.0http
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Ben Wilson avatar image Ben Wilson ♦♦ commented ·

Hi @Shuo C2, was jason.lightfoot's answer helpful? If so, please click the red "Accept" button on their answer. Or if you still have questions, add a comment and we'll continue the conversation.

If we haven't heard back from you within 3 business days we'll auto-accept an answer, but you can always unaccept and comment back to reopen your question.

0 Likes 0 ·

1 Answer

Jason Lightfoot avatar image
1 Like"
Jason Lightfoot answered Shuo C2 commented

Remove the "https://" from the host path - just use "www.google.com", so:

request.host = "www.google.com";

Or initialize the request like this:

Http.Request request= Http.Request("https://www.google.com");
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Shuo C2 avatar image Shuo C2 commented ·

Thanks, moving the url into Http.Request seems to have solved the issue and I'm able to elicit a server response.

Is there a way to change the content-type of the request? It seems by default to be

application/x-www-form-urlencoded

I'd like to change it to

application/json
0 Likes 0 ·