× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Solved.

For the record when calling http_url_post for example if no contentType is
passed on the call then by default httpapi will set a default content type
of Content-Type: text/xml

So to resolve my problem I did the following;

Removed the Content-Type: application/json from my Header string.

Set the content type on the call to http_url_post

I also needed to set the time out to -1 so as to use the default time out
(zero sets the time out to zero)

// Set the required headers excluding content type
http_xproc( HTTP_POINT_ADDL_HEADER
: %paddr(tripHeaders) );

// Set Content type and other defaults
contentType = 'application/json' ;
timeout = -1 ;
userAgent = *blanks ;

// post the data
rc = http_url_post(uri
: %addr(myjsontrips) + 2
: %len(%trim(myjsontrips))
: jsonfilename2
: timeout
: userAgent
: contentType ) ;

Post was successful and no duplicate content-Type in the header.

Don Brown


"MIDRANGE-L" <midrange-l-bounces@xxxxxxxxxxxxxxxxxx> wrote on 16/02/2019
10:53:26 PM:

From: "Don Brown" <DBrown@xxxxxxxxxx>
To: "Midrange Systems Technical Discussion"
<midrange-l@xxxxxxxxxxxxxxxxxx>
Date: 16/02/2019 10:53 PM
Subject: HTTPAPI Error - Duplicate Header
Sent by: "MIDRANGE-L" <midrange-l-bounces@xxxxxxxxxxxxxxxxxx>

Note: ftpapi@xxxxxxxxxxxxxxxxxxxxxx mailing list is still not
operational.


I am having a problem where I am receiving the error of a Duplicate
Header

The test program I am writing retrieves a token from a REST service and
then uses the authentication token to POST json data to the REST
Service.

I am using http_xproc( HTTP_POINT_ADDL_HEADER to set the header
authentication details.

The request to retrieve the token succeeds but then I need to set new
headers to be able to POST the json data.

I can not find an option to Clear the header.

The debug log is showing two Content-Types and I think based on the
error
message this is the reason for the error.

The code and debug log is below.

Hoping someone has come across this issue and can advise how to resolve
it.

Thanks

Relevant code snippet and Debug log follows;

uri = 'https://uat.api.onegov.nsw.gov.au/+
/oauth/client_credential/accesstoken+
?grant_type=client_credentials';

http_xproc( HTTP_POINT_ADDL_HEADER
: %paddr(tokenHeaders) );

rc = http_url_get(uri: jsonFileName );
if (rc <> 1);
http_crash();
endif;

Data-into aaaaa %Data( jsonFileName :
'doc=file case=convert countprefix=num_')
%Parser( 'YAJL72/YAJLINTO' );


myjsonTrips = '{ +
"rideshareDetail": +
{ +
"submittedDateFrom": "01/01/2018 05:12:12 AM", +
"submittedDateTo": "01/02/2018 05:12:56 PM", +
"vehicleRegistration": "test", +
"policyNumber": "", +
"ctpInsurer": "", +
"tripDetail": [ +
{ +
"tripId": "BBR1009", +
"tripStartDateTime": "02/01/2018 10:45:12 AM", +
"tripEndDateTime": "05/01/2018 12:45:12 PM", +
"tripDistance": "15", +
"tripStartPostcode": "2000", +
"tripStartSuburb": "SYDNEY", +
"tripAmount": "20.30" +
}, +
{ +
"tripId": "BBR1505", +
"tripStartDateTime": "07/01/2018 01:15:56 PM", +
"tripEndDateTime": "08/01/2018 02:30:00 PM", +
"tripDistance": "15", +
"tripDistance": "15", +
"tripStartPostcode": "2000", +
"tripStartSuburb": "SYDNEY", +
"tripAmount": "20.30" +
} +
] +
} +
}' ;

http_xproc( HTTP_POINT_ADDL_HEADER
: %paddr(tripHeaders) );

uri = 'https://uat.api.onegov.nsw.gov.au+
/P2PRideshare/v1/operator/tripdetails/submit';

rc = http_url_post(uri
: %addr(myjsontrips) + 2
: %len(%trim(myjsontrips))
: jsonfilename2) ;

P tokenHeaders B
D tokenHeaders PI
D Header 1024A varying
D UserData * value
/free
Header = 'Postman-Token: f6a0e906-b1cf-4e13-8da8-023274871bd4'
+ x'0d25'
+ ' apikey: WmTFrOi8ZXBa0RBn6Tx2vYd3dnkOgtjj'
+ x'0d25'
+ 'authorization: Basic +
V21URnJPaThaWEJhMFJCbjZUeDJ2WWQzZG5rT2d0amo6cnRUcjk5amtockNhV0Z0aA'

+ x'0d25'
+ 'cache-control: no-cache'
+ x'0d25';
/end-free
P E

P tripHeaders B
D tripHeaders PI
D Header 1024A varying
D UserData * value
/free
Header = 'Content-Type: application/json'
+ x'0d25'
+ 'Postman-Token: 5becf8a5-db3c-4cf7-8941-3d38e4b9343b'
+ x'0d25'
+ 'apikey: WmTFrOi8ZXBa0RBn6Tx2vYd3dnkOgtjj'
+ x'0d25'
+ 'authorization: Bearer ' + %trim(aaaaa.access_Token)
+ x'0d25'
+ 'transactionID: 22245678'
+ x'0d25'
+ 'requestTimeStamp: 04/06/2018 03:10:22 pm'
+ x'0d25'
+ 'cache-control: no-cache'
+ x'0d25'
+ 'userID: Don'
+ x'0d25';
/end-free
P E


Debug Log

HTTPAPI Ver 1.24 released 2012-01-23
OS/400 Ver V7R3M0

New iconv() objects set, PostRem=819. PostLoc=0. ProtRem=819. ProtLoc=0
http_url_post(): entered
http_persist_open(): entered
http_long_ParseURL(): entered
DNS resolver retrans: 2
DNS resolver retry : 2
DNS resolver options: x'00000136'
DNS default domain: MSD.LOCAL
DNS server found: 10.1.1.31
DNS server found: 8.8.8.8
https_init(): entered

SetError() #49: SSL_protocol: Unknown protocol 596
Protocol Used:
http_persist_post(): entered
http_persist_req(POST) entered.
http_long_ParseURL(): entered
do_oper(POST): entered
There are 0 cookies in the cache
POST /P2PRideshare/v1/operator/tripdetails/submit HTTP/1.1
Host: uat.api.onegov.nsw.gov.au
User-Agent: http-api/1.24
Content-Type: text/xml
Content-Length: 644
Content-Type: application/json
Postman-Token: 5becf8a5-db3c-4cf7-8941-3d38e4b9343b
apikey: WmTFrOi8ZXBa0RBn6Tx2vYd3dnkOgtjj
authorization: Bearer 7ewaNweVb0Y5Odu8ikSaAfZjkoqA
transactionID: 22245678
requestTimeStamp: 04/06/2018 03:10:22 pm
cache-control: no-cache
userID: Don.Brown@xxxxxxxxxx

senddoc(): entered
{ "rideshareDetail": { "submittedDateFrom": "01/01/2018 05:12:12 AM",
recvresp(): entered
HTTP/1.1 400 Bad Request
Date: Sat, 16 Feb 2019 05:58:07 GMT
Content-Type: application/json
Content-Length: 116
Connection: keep-alive
X-Frame-Options: DENY
Strict-Transport-Security: max-age=86400
X-Content-Type-Options: nosniff
Content-Security-Policy: frame-ancestors 'none'
X-XSS-Protection: 1

SetError() #13: HTTP/1.1 400 Bad Request
recvresp(): end with 400
recvdoc parms: identity 116
header_load_cookies() entered
recvdoc(): entered
SetError() #0:
{"fault":{"faultstring":"Duplicate Header

\"Content-Type\"","detail":{"errorcode":"protocol.http.DuplicateHeader"}}}


SetError() #13: HTTP/1.1 400 Bad Request
http_close(): entered


Don Brown




______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud
service.
For more information please visit http://www.symanteccloud.com
______________________________________________________________________
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
list
To post a message email: MIDRANGE-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/midrange-l.

Please contact support@xxxxxxxxxxxx for any subscription related
questions.

Help support midrange.com by shopping at amazon.com with our affiliate
link:
https://amazon.midrange.com

______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud
service.
For more information please visit http://www.symanteccloud.com
______________________________________________________________________


______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud service.
For more information please visit http://www.symanteccloud.com
______________________________________________________________________

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.