Page 1 of 2
http request - post
Posted: Mon Dec 29, 2014 2:08 pm
by ArielRauch
how can I specify the header with the new http request element?
I specifically need to specify the Content-Type
http request - post
Posted: Mon Dec 29, 2014 3:14 pm
by gabrielp
From the documentation:
The 'Content-Type' HTTP request header is automatically added to the request with the value
"application/x-www-form-urlencoded" (which means the request contains HTML form input
data).
There is an option for adding a header, but I'm not sure if Switch will be smart enough to remove the Content-Type header it already added. Maybe give this a shot anyway?
theHTTP.addHeader( "Content-Type", "application/vnd.cip4-jmf+xml" );
If that doesn't work, perhaps this before you addHeader:
theHTTP.resetHeaders();
But it looks like the resetHeaders method only works on headers added by addHeader.
If there really isn't a way to change the content type, then the HTTP class surely just got a lot less valuable and we might find ourselves stuck using cURL.
http request - post
Posted: Mon Dec 29, 2014 3:18 pm
by ArielRauch
thanks, Gabriel!
I actually was trying to use the flow element HTTP request. I assume that this is not suitable.
Where is the documentation for the HTTP class?
Thanks
Ariel
http request - post
Posted: Mon Dec 29, 2014 4:15 pm
by ArielRauch
ok found the updated documentation.
As far as I understand the flow element "HTTP request" does not give any option to add or change the content-type header.
Anyone?
http request - post
Posted: Mon Dec 29, 2014 4:23 pm
by gabrielp
ArielRauch wrote: ok found the updated documentation.
As far as I understand the flow element "HTTP request" does not give any option to add or change the content-type header.
Anyone?
It appears there is an option for specifying a mime-type (which is what content-type on an HTTP request is) but I'm unclear of how it works.
http request - post
Posted: Mon Dec 29, 2014 4:24 pm
by ArielRauch
I am stuck there too:)
Dwight - please enlight(en):)
http request - post
Posted: Mon Dec 29, 2014 4:35 pm
by ArielRauch
ok - I think I made it work - with a script.
I added the content-type as a header and I received the response.
Haleluya - might be appropriate for those times
http request - post
Posted: Mon Dec 29, 2014 4:37 pm
by gabrielp
ArielRauch wrote: ok - I think I made it work - with a script.
I added the content-type as a header and I received the response.
Glad it worked out and it's good to know there is a solution. I knew I would have this problem eventually once I started sending JMF with the new HTTP class.
http request - post
Posted: Mon Dec 29, 2014 4:43 pm
by ArielRauch
Below please see the very raw code of how to get response from the dfe:
function jobArrived( s : Switch, job : Job )
{
var theHTTP = new HTTP();
theHTTP.setAttachedFile( job.getPath() );
theHTTP.url = "
http://172.16.200.50:8080/prodflow/jmf/dfe";
theHTTP.addHeader("Content-Type","application/vnd.cip4-jmf+xml");
theHTTP.post();
job.log( 3, "Upload started", 100);
while( !theHTTP.waitForFinished( 3 ) ) {
job.log( 3, "Uploading...", theHTTP.progress() );
}
job.log( 3, "Upload finished" );
job.log( 3, "Server response: %1", theHTTP.getServerResponse().toString( "UTF-8" ) );
if( theHTTP.finishedStatus == HTTP.Ok && theHTTP.statusCode == 200 ) {
job.log( 3, "Upload completed successfully" );
}
else {
job.fail( "Upload failed with the status code %1", theHTTP.statusCode );
return;
}
job.sendToSingle( job.getPath() );
}
The asynchronous part which is solved with the while loop is not very elegant.
I think we need to think about it a bit
http request - post
Posted: Mon Dec 29, 2014 5:41 pm
by gabrielp
ArielRauch wrote: Below please see the very raw code of how to get response from the dfe:
Very cool. It's nice to see it in action. Thanks for sharing!
http request - post
Posted: Mon Jan 05, 2015 3:51 pm
by freddyp
ArielRauch wrote: The asynchronous part which is solved with the while loop is not very elegant.
I think we need to think about it a bit
Do not think about it: the post, put, get and del functions of an HTTP object are executed asynchronously. That is how it is.
I am glad to see that the new HTTP class is quickly finding some useful applications in the Switch community
Freddy
Re: http request - post
Posted: Thu Jun 15, 2017 9:31 pm
by actionHero
Hello,
I'm trying to PUT to my AWS API Gateway. I have a Lambda Function that doesn't require the AWS Keys to perform the PUT. This works in Postman perfectly. In Switch I get "HTTP PUT request error: error during handshake[2]: 0x80090326" which is an error in authentication.
Any Ideas?
function jobArrived( s : Switch, job : Job )
{
var aws = new HTTP( HTTP.SSL );
aws.url = "https://My_AWS_API";
aws.authScheme = HTTP.NoneAuth;
aws.setAttachedFile( job.getPath() );
var theResponseFilePath = job.createPathWithName( job.getNameProper(), false );
aws.localFilePath = theResponseFilePath;
aws.addHeader( "Content-Type", "application/json" );
aws.addHeader( "Authorization", "allow" );
aws.put();
while( !aws.waitForFinished( 3 ) ) { }
job.log( 1, "Request finish status: %1", aws.finishedStatus );
job.sendToSingle( theResponseFilePath );
}
Re: http request - post
Posted: Thu Jun 15, 2017 10:15 pm
by gabrielp
It doesn't give you a response code or body from the server? You don't need to provide any authentication for your API Gateway?
Re: http request - post
Posted: Thu Jun 15, 2017 10:22 pm
by actionHero
The error I am getting is "HTTP GET request error: error during handshake[2]: 0x80090326" It's returning HTTP error code 0, which is not a valid error. Which leads me to believe that it's not authenticating.
Lambda is authenticating based on the header "Authorization:allow".
Postman code that works:
PUT /test/CustomerID HTTP/1.1
Host: blahblah.execute-api.us-east-1.amazonaws.com
Content-Type: application/json
Authorization: allow
Cache-Control: no-cache
Postman-Token: e861a868-05aa-fb76-618a-b81a7226ce01
{
"CustomerID": "000100",
"CustomerNm": "AWS is NOT Cool",
"Date": "01/12/2017",
"Shipping": "USPS",
"commentId": "Hello World"
}
Re: http request - post
Posted: Thu Jun 15, 2017 10:31 pm
by gabrielp
An HTTP request should have an HTTP status code and message on response.
Try and print it out to see what it is:
Code: Select all
if( theHTTP.finishedStatus == HTTP.Ok && theHTTP.statusCode == 200
&& File.exists( theHTTP.localFilePath ) )
{
job.log( 1, "Request completed successfully" );
}
else
{
job.fail( "Request failed with the status code %1", theHTTP.statusCode );
return;
}
}