http request - post
-
- Advanced member
- Posts: 230
- Joined: Thu Aug 07, 2014 10:04 am
http request - post
how can I specify the header with the new http request element?
I specifically need to specify the Content-Type
I specifically need to specify the Content-Type
http request - post
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.
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.
Chat: open-automation @ gitter
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
-
- Advanced member
- Posts: 230
- Joined: Thu Aug 07, 2014 10:04 am
http request - post
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
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
-
- Advanced member
- Posts: 230
- Joined: Thu Aug 07, 2014 10:04 am
http request - post
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?
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
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.
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.
Chat: open-automation @ gitter
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
-
- Advanced member
- Posts: 230
- Joined: Thu Aug 07, 2014 10:04 am
http request - post
I am stuck there too:)
Dwight - please enlight(en):)
Dwight - please enlight(en):)
-
- Advanced member
- Posts: 230
- Joined: Thu Aug 07, 2014 10:04 am
http request - post
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
I added the content-type as a header and I received the response.
Haleluya - might be appropriate for those times
http request - post
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.
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.
Chat: open-automation @ gitter
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
-
- Advanced member
- Posts: 230
- Joined: Thu Aug 07, 2014 10:04 am
http request - post
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
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
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!
Very cool. It's nice to see it in action. Thanks for sharing!
Chat: open-automation @ gitter
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
http request - post
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
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
-
- Newbie
- Posts: 15
- Joined: Thu May 18, 2017 12:06 am
Re: http request - post
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 );
}
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
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?
Chat: open-automation @ gitter
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
-
- Newbie
- Posts: 15
- Joined: Thu May 18, 2017 12:06 am
Re: http request - post
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"
}
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
An HTTP request should have an HTTP status code and message on response.
Try and print it out to see what it is:
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;
}
}
Chat: open-automation @ gitter
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix