Page 1 of 1

400 Bad Request

Posted: Thu Jun 01, 2023 3:09 pm
by moni_66
Hello,
this is my first time using httpapi functions and I need some help.
I have to send a string to an external webservice and the external company provided me a command that work fine.
I tried to replicate it into rpgle program, but when I run the program I developed, I get 400 Bad Request error.
What am I doing wrong?
The original command is:

Code: Select all

curl --location 'https://api-qty.company.com/gateway/ch-dw2000/v1/files/sample' --header 'X-COMPANY-TRANSACTIONID: EsempioCSVdaDW2000.csv' --header 'Content-Type: text/plain' --header 'Authorization: Bearer eyJraWQiOiI1OGE3NzBkMC03MWFlLTExZWQtOWUwYS1iZGMzMzY3MDA4NGQiLCJhbGciOiJSUzI1NiJ9.eyJjbGllbnRfaWQiOiI2Mzc1MjUyNi0yNGRmLTRiYjgtOWUwZC0wMmE4ZjU3YTFhYWMiLCJpc3MiOiJodHRwczovL2F1dGhndy1xdHkuYm9uZmlnbGlvbGkuY29tL2FzIiwiaWF0IjoxNjg1NjIyNzI2LCJleHAiOjE2ODU2MjYzMjYsImF1ZCI6WyJBUEkiXSwic2NvcGUiOiJhcGktaXQtZGlnaXRhbCJ9.SLa-JOCZUwDKN9xOTenymThoGXSOc5xvdl3cWOlYgZIdPLi54L-Hns-gPYU0Rk5lhnD675nl4Qj__j7zGkqvBbbC8aVQimu0l_0JDA-Bxl9ys2c2yvem-hngN5csdindlXe5xDSxMr7nozKLs8I-hVwvBn98KVnOEV6f_JxWjx--zYScmsIcmDd60DmpEli8So2Oaixvjc5atfuICWf9b3IeWxyiiaF8I3iX6jqwGFyo14RvFdDTe7g1LAeQh6Ul7Sai54V-1r3IxQ8Kr9uW_RYbJCW37xfKsPDCNl5GKSoSRntxuJQffltMeu7jRDx7AaA7KJbF9Aa-gpubE3wfKg' --data 'Field1|Field2|Field3 /n Riga1_F1|Riga1_F2|Riga1_F3 /n Riga2_F1|Riga2_F2|Riga2_F3 /n Riga3_F1|Riga3_F2|Riga3_F3 /n'

This is my program

Code: Select all

  
     d rtcd            s              1a                                                                                                             
     d psds          esds                                                                                                                            

     d url             s            256a   inz                                                                                                       
     d poststring      s          32760a   inz                                                                                                       
     d contenttype     s          16384a   varying inz('application/x-www-f-                                                                         
     d                                     orm-urlencoded')                                                                                          
     d dsresult        ds                                                                                                                            
     d   errdes                     500    inz                                                                                                       
     d   errnro                      10i 0 inz                                                                                                       
     d   rspcod                      10i 0 inz(200)                                                                                                  
     d rc1             s             10i 0                                                                                                           
     D Add_Headers     PR                                                                                                                            
     D   Header                    1024A   varying                                                                                                   
     D   UserData                      *   value                                                                                                     
     d entry           pr                  extpgm('BONFIDAT')                                                                                        
     d   token                     1000a                                                                                                             
     d entry           pi                                                                                                                            
     d   token                     1000a                                                                                                             
      /free                                                                                                                                          
        // The command to replicate is                                                                                                
        // curl --location 'https://api-qty.company.com/gateway/ch-dw2000/v1/files/sample'                                                       
        // --header 'X-COMPANY-TRANSACTIONID: EsempioCSVdaDW2000.csv'                                                                            
        // --header 'Content-Type: text/plain'                                                                                                       
        // --header 'Authorization: Bearer eyJraWQiOiI1OGE3NzBkMC03MWFlLTExZWQtOWUwYS.....ffltMeu7jRDx7AaA7KJbF9Aa-gpubE3wfKg
        // --data 'Field1|Field2|Field3 /n Riga1_F1|Riga1_F2|Riga1_F3 /n                                                                             
        //    Riga2_F1|Riga2_F2|Riga2_F3 /n Riga3_F1|Riga3_F2|Riga3_F3 /n' 
        
        callp http_debug(*ON:'/users/mob/bonfidat_debug.txt');   
        
        // Url to send                                                                                                                    
        url = 'https://api-qty.company.com/gateway/'                                                                                             
          + 'ch-dw2000/v1/files/sample';      
          
        // setting headers                                                
        http_xproc(HTTP_POINT_ADDL_HEADER : %paddr(Add_Headers));                                                                                    
        http_setOption('content-type':'text/plain');    
        
        // set authorization via token                                                                                                     
        http_setAuth(HTTP_AUTH_NONE:'':'');                                                                                                          
        http_setAuth(HTTP_AUTH_BEARER:'':%trim(token));  
        
        // prepare data to send                                                                                 
        postString = 'Field1|Field2|Field3 /n Riga1_F1|Riga1_F2|Riga1_F3 /n'                                                                         
           + ' Riga2_F1|Riga2_F2|Riga2_F3 /n Riga3_F1|Riga3_F2|Riga3_F3 /n';      
           
        monitor;                                                                                                                                     
          rc1 = http_post(%trim(url)                                                                                                                        
            : %Addr(postString) + 2                                                                                                                  
            : %Len(postString)                                                                                                                       
            : '/users/mob/inviobonfi.txt'                                                                                                            
            : HTTP_TIMEOUT                                                                                                                           
            : HTTP_USERAGENT                                                                                                                         
            : 'text/plain' );                                                                                                                        
        on-error *all;                                                                                                                               
          errdes = http_error(errnro:rspcod);                                                                                                        
        endmon;                                                                                                                                      
        if rc1 <> 1;                                                                                                                                 
          // handle error                                                                                                                            
        endif;                                                                                                                                       
        callp http_debug(*OFF);  
        
        // fine sofferenze                                                                                                                           
        exsr exit;                                                                                                                                   
                                                                                                                                                     
        // subroutines                                                                                                                               
                                                                                                                                                     
        begsr *pssr;                                                                                                                                 
          dump PsDsPgmNam;                                                                                                                           
          *inlr = '1';                                                                                                                               
          return;                                                                                                                                    
        endsr;                                                                                                                                       
                                                                                                                                                     
        begsr exit;                                                                                                                                  
          *inlr = '1';                                                                                                                               
          return;                                                                                                                                    
        endsr;                                                                                                                                       
                                                                                                                        
     P Add_Headers     B                                                                                                                             
     D Add_Headers     PI                                                                                                                            
     D   Header                    1024A   varying                                                                                                   
     D   UserData                      *   value                                                                                                     
      /free                                                                                                                                          
        Header = 'X-COMPANY-TRANSACTIONID: '                                                                                                     
          + 'EsempioCSVdaDW2000.csv'                                                                                                                 
          + x'0d25';                                                                                                                                 
      /end-free                                                                                                                                      
     P                 E          
And this is the debug file

Code: Select all

HTTPAPI Ver 1.45 released 2021-09-20
NTLM Ver 1.4.0 released 2014-12-22
OS/400 Ver V7R4M0

http_setauth(): entered
http_setauth(): entered
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: mycompany
DNS server found: 10.0.xx.xxx
DNS server found: 10.0.xxx.xxx
DNS server found: 212.xxx.xxx.xxx
Nagle's algorithm (TCP_NODELAY) disabled.
SNI hostname set to: api-qty.company.com
-------------------------------------------------------------------------------------
Dump of server-side certificate information:
-------------------------------------------------------------------------------------
Cert Validation Code = 6000
-----BEGIN CERTIFICATE-----
MIIIXDCCB0SgAwIBAgIQC9R9igM8ZAcXWkK4LZZ96DANBgkqhkiG9w0BAQsFADBe
MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
d3cuZGlnaWNlcnQuY29tMR0wGwYDVQQDExRHZW9UcnVzdCBSU0EgQ0EgMjAxODAe
Fw0yMjA5MDEwMDAwMDBaFw0yMzEwMDIyMzU5NTlaMGQxCzAJBgNVBAYTAklUMRow
GAYDVQQHExFDYWxkZXJhcmEgZGkgUmVubzEbMBkGA1UEChMSQm9uZmlnbGlvbGkg
Uy5wLkEuMRwwGgYDVQQDExNhcGkuYm9uZmlnbGlvbGkuY29tMIICIjANBgkqhkiG
9w0BAQEFAAOCAg8AMIICCgKCAgEAzMC9mrsHnC8hFoJPstGd+mOG3PCSq25EvDBD
lR+p1kO7tgP/gMlwGYRUj2WpfKfOSASeiIfYHmlILJ4XAYzqhiIek/VwyxIp4gFm
k/7AB+BnCoBDkbRHGgt6nGrFHJ1BcvoHYdH532tDHYFEJEJPoJA8qLi2UTizQ1Nk
mz9jxOIvrxfSQ3hIGdi0TGhHGqja83fUOEOCBulmL1BhtMQsXA02KNcT7dWcVV/a
wWOG5NTvdF8x3XWa/bvRdd1ORD1JEuhJPGvjw5tinIz3/xMxt4x0BcCvjtM0o6MS
9HqBswc5s/mVogYJs/TUXc8U0AQs7R3wqcjHxAU7SzfmKr63W+uXO3mZAKAPVAbr
a8IBE0ZhNZyS/J3BKsdkXm9fBIGz2VlMXmZ2xTHge7nb4XAAQBYFGww4i3oEp6M4
Q5vvFg0KvXSbOMH7T3dXPjXgPVTl1W1/+RlCxb/3+9s25mO7N9zATG6Grqt4WCw2
Gbv2LT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U0FDQTIwMTguY3J0MAkGA1UdEwQCMAAwggF/Bgor
BgEEAdZ5AgQCBIIBbwSCAWsBaQB3AOg+0No+9QY1MudXKLyJa8kD08vREWvs62nh
d31tBr1uAAABgvgtm8wAAAQDAEgwRgIhAOuzb8ORpqyiQjmtQlmnsqF2fGUB6rHN
QTyNa30Ncqb8AiEA2yr4DSjIB/XW3XlfxCbw5Rrq1x88TvVJruNhsBHZTFoAdgA1
zxkbv7FsV78PrUxtQsu7ticgJlHqP+Eq76gDwzvWTAAAAYL4LZv8AAAEAwBHMEUC
IBQxNjxmsoAUjWeVRGub2Fk+Pc2ZpQ6VichjEZE/3B2IAiEA/FRHBSFj0Q4cAQuF
Dx901kf64L790wPv/uFd3fcxUOIAdgCzc3cH4YRQ+GOG1gWp3BEJSnktsWcMC4fc
8AMOeTalmgAAAYL4LZw9AAAEAwBHMEUCIQC6b2vVIdpPyqf9UEqHKu8C/tGPcR2b
yfV780ypXtX+FwIgNOGLJBszwcDek2Qq3QOVysyUNuG+hU79hNKd3O7uLIowDQYJ
KoZIhvcNAQELBQADggEBAAG7c8OtnKQgBSHSC7+893hbZ5ck+JiVSXDt6OFXcoVp
va8WJewdNpmms5HIiiEKSZwyHKcvvxgtXvizeRfUH3fMbZtdZoczFiIAlf04pgPw
lLdFFDNhKFnss4xBQEhXhkJ0PPz5Mf07pRGFL14q5PM1KZIrY/uaktbsX1d0XsIc
3/Y2SkLbcLJz7M6U++6c9sp3JHd7TOmK0w/FcKKBqQW7aDxUds+zP4+0M7ILGGrL
CqpWePdOn8vo4zowL9Ere57rYkBgbhEa9Ot+9tUXsOxfjU0/wtselkRVu+tLzP/B
7ADjKjZKQwCbWR9nUt9kpBzGLtSJl22eM4dee/pzlAY=
-----END CERTIFICATE-----
Serial Number: 0B:D4:7D:8A:03:3C:64:07:17:5A:42:B8:2D:96:7D:E8
Common Name: api.company.com
Country: IT
Locality: xxx
Org Unit: Company S.p.A.
Issuer CN: GeoTrust RSA CA 2018
Issuer Country: US
Issuer Org: DigiCert Inc
Issuer Org Unit: www.digicert.com
Version: 3
not before: 20220901020000
Unknown Field: 02:00:00 01-09-2022
not after: 20231003015959
Unknown Field: 01:59:59 03-10-2023
pub key alg: 1.2.840.113549.1.1.1
signature algorithm: 1.2.840.113549.1.1.11
Unknown Field: 0382020F003082020A0282020100CCC0BD9ABB079C2F2116824FB2D19DFA6386DCF092AB6E44BC3043951FA9D643BBB603FF80C9701984548F65A97CA7CE48049E8887D81E69482C9E17018CEA86221E93F570CB1229E2016693FEC007E0670A804391B4471A0B7A9C6AC51C9D4172FA0761D1F9DF6B431D814424424FA0903CA8B8B65138B34353649B3F63C4E22FAF17D243784819D8B44C68471AA8DAF377D438438206E9662F5061B4C42C5C0D3628D713EDD59C555FDAC16386E4D4EF745F31DD759AFDBBD175DD4E443D4912E8493C6BE3C39B629C8CF7FF1331B78C7405C0AF8ED334A3A312F47A81B30739B3F995A20609B3F4D45DCF14D0042CED1DF0A9C8C7C4053B4B37E62ABEB75BEB973B799900A00F5406EB6BC201134661359C92FC9DC12AC7645E6F5F0481B3D9594C5E6676C531E07BB9DBE170004016051B0C388B7A04A7A338439BEF160D0ABD749B38C1FB4F77573E35E03D54E5D56D7FF91942C5BFF7FBDB36E663BB37DCC04C6E86AEAB78582C3619BBF62D3629FF6228EE026410532CA390CCB6C55C8DEB48123F296396B45607807A15F4DACFD63F40BB422A1C1CA68BA6AAE68A35A4D155D7521E9BFBFC0E7D305C3F604963025968A76885CA60FF02AB4F26C5D8F0F1E6531AB6D1C0B1C7D92A375959F4129B244C3A0505C88BC3AA3F30F7003BA92222FF4C6668F8E608A5E017E57E895FC4117E2D034476FD88ED62865A59950203010001
Unknown Field: 4096
Unknown Field: C4462CCB6C9327EBEB9816A7E0456706
Unknown Field: 1.2.840.113549.2.5
Unknown Field: 1EA4315CFB7863E692CFE31F61763839C826949D
Unknown Field: E6DCB12F56C9F000776303467C12F5AC7F3232AD75925966DEC76C1EABBC7C30
Unknown Field: 5
Unknown Field: api.company.com
Unknown Field: 0
Unknown Field: 1.3.6.1.5.5.7.3.2
Unknown Field: 1.3.6.1.5.5.7.3.1
Unknown Field: 2.23.140.1.2.2
Unknown Field: http://status.geotrust.com

Protocol Used: TLS Version 1.2
http_persist_post(): entered
http_persist_req(POST) entered.
http_long_ParseURL(): entered
http_long_ParseURL(): entered
do_oper(POST): entered
There are 1 cookies in the cache
cookie=ssnid not sent (expired)
POST /gateway/ch-dw2000/v1/files/sample HTTP/1.1
Host: api-qty.company.com
User-Agent: http-api/1.45
Content-Type: text/plain
Content-Length: 32760
Authorization: Bearer eyJraWQiOiI1OGE3NzBkMC03MWFlLTExZWQtOWUwYS1iZGMzMzY3MDA4NGQiLCJhbGciOiJSUzI1NiJ9.eyJjbGllbnRfaWQiOiI2Mzc1MjUyNi0yNGRmLTRiYjgtOWUwZC0wMmE4ZjU3YTFhYWMiLCJpc3MiOiJodHRwczovL2F1dGhndy1xdHkuYm9uZmlnbGlvbGkuY29tL2FzIiwiaWF0IjoxNjg1NjIyNzI2LCJleHAiOjE2ODU2MjYzMjYsImF1ZCI6WyJBUEkiXSwic2NvcGUiOiJhcGktaXQtZGlnaXRhbCJ9.SLa-JOCZUwDKN9xOTenymThoGXSOc5xvdl3cWOlYgZIdPLi54L-Hns-gPYU0Rk5lhnD675nl4Qj__j7zGkqvBbbC8aVQimu0l_0JDA-Bxl9ys2c2yvem-hngN5csdindlXe5xDSxMr7nozKLs8I-hVwvBn98KVnOEV6f_JxWjx--zYScmsIcmDd60DmpEli8So2Oaixvjc5atfuICWf9b3IeWxyiiaF8I3iX6jqwGFyo14RvFdDTe7g1LAeQh6Ul7Sai54V-1r3IxQ8Kr9uW_RYbJCW37xfKsPDCNl5GKSoSRntxuJQffltMeu7jRDx7AaA7KJbF9Aa-gpubE3wfKg 
X-COMPANY-TRANSACTIONID: EsempioCSVdaDW2000.csv


senddoc(): entered
eld1|Field2|Field3 /n Riga1_F1|Riga1_F2|Riga1_F3 /n Riga2_F1|Riga2_F2|Riga2_F3 /n Riga3_F1|Riga3_F2|Riga3_F3 /n                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
                   
                   
                   
                   
                   
                   
                   
recvresp(): entered
HTTP/1.1 400 Bad Request                          
Date: Thu, 01 Jun 2023 14:11:38 GMT               
Content-Type: text/html                           
Content-Length: 150                               
Connection: close                                 
Server: APIGW                                     
                                                  
                                                  
SetError() £13: HTTP/1.1 400 Bad Request          
recvresp(): end with 400                          
recvdoc parms: identity 150                       
header_load_cookies() entered                     
recvdoc(): entered                                
SetError() £0:                                    
recvdoc(): Receiving 150 bytes.                   
<html>                                            
<head><title>400 Bad Request</title></head>       
<body>                                            
<center><h1>400 Bad Request</h1></center>
<hr><center>nginx</center>               
</body>                                  
</html>                                  
                                         
SetError() £13: HTTP/1.1 400 Bad Request 
http_close(): entered                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
Thank you for the support you can provide me

Monica

Re: 400 Bad Request

Posted: Fri Jun 02, 2023 12:02 am
by Scott Klement
I'm not sure what the purpose of the /n is in your data. Often people use \n (with a backslash) as shorthand for a newline character. Though, yours has a foreslash (/n) which is not quite the same -- but I'm still thinking perhaps it was meant for you to use a newline character in your data rather than literally providing the "/n" characters?

in RPG, you would typically do that like this:

Code: Select all

postString = 'Field1|Field2|Field3' + x'25'
           + 'Riga1_F1|Riga1_F2|Riga1_F3' + x'25'
           + 'Riga2_F1|Riga2_F2|Riga2_F3' + x'25'
           + 'Riga3_F1|Riga3_F2|Riga3_F3' + x'25';   
(possibly also with a space before the x'25'? But that is unusual.)

Also please consider using http_req instead of the old http_post -- http_post is "old school".

Re: 400 Bad Request

Posted: Fri Jun 02, 2023 12:03 pm
by moni_66
Thank you Scott, today is vacation in Italy, on monday I'll try your suggest.

Re: 400 Bad Request

Posted: Mon Jun 05, 2023 8:02 am
by moni_66
Hi Scott,
I changed my program as you suggested

Code: Select all

postString = 'Field1|Field2|Field3' + x'25'        
           + 'Riga1_F1|Riga1_F2|Riga1_F3' + x'25'  
           + 'Riga2_F1|Riga2_F2|Riga2_F3' + x'25'  
           + 'Riga3_F1|Riga3_F2|Riga3_F3' + x'25'; 
and

Code: Select all

rc1 = http_req( 'POST'                                          
             : %trim(url)                                       
             : '/users/mob/inviobonfi.txt'// File to receive    
             : *omit                      // String to receive  
             : *omit                      // File to send       
             : postString                 // String to send     
             : contenttype);              // Content type       (text/plain)
but the result doesn't change.
This is the debug file

Code: Select all

HTTPAPI Ver 1.45 released 2021-09-20                                                  
NTLM Ver 1.4.0 released 2014-12-22                                                    
OS/400 Ver V7R4M0                                                                     
                                                                                      
http_setauth(): entered                                                               
http_setauth(): 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: mycompany                                                            
DNS server found: 10.0.250.131                                                        
DNS server found: 10.0.254.251                                                        
DNS server found: 212.216.112.112                                                     
Nagle's algorithm (TCP_NODELAY) disabled.                                             
SNI hostname set to: api-qty.company.com                                          
-------------------------------------------------------------------------------------
Dump of server-side certificate information:                    
----------------------------------------------------------------
Cert Validation Code = 6000                                     
-----BEGIN CERTIFICATE-----                                     
MIIIXDCCB0SgAwIBAgIQC9R9igM8ZAcXWkK4LZZ96DANBgkqhkiG9w0BAQsFADBe
MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
d3cuZGlnaWNlcnQuY29tMR0wGwYDVQQDExRHZW9UcnVzdCBSU0EgQ0EgMjAxODAe
Fw0yMjA5MDEwMDAwMDBaFw0yMzEwMDIyMzU5NTlaMGQxCzAJBgNVBAYTAklUMRow
GAYDVQQHExFDYWxkZXJhcmEgZGkgUmVubzEbMBkGA1UEChMSQm9uZmlnbGlvbGkg
Uy5wLkEuMRwwGgYDVQQDExNhcGkuYm9uZmlnbGlvbGkuY29tMIICIjANBgkqhkiG
9w0BAQEFAAOCAg8AMIICCgKCAgEAzMC9mrsHnC8hFoJPstGd+mOG3PCSq25EvDBD
lR+p1kO7tgP/gMlwGYRUj2WpfKfOSASeiIfYHmlILJ4XAYzqhiIek/VwyxIp4gFm
k/7AB+BnCoBDkbRHGgt6nGrFHJ1BcvoHYdH532tDHYFEJEJPoJA8qLi2UTizQ1Nk
mz9jxOIvrxfSQ3hIGdi0TGhHGqja83fUOEOCBulmL1BhtMQsXA02KNcT7dWcVV/a
wWOG5NTvdF8x3XWa/bvRdd1ORD1JEuhJPGvjw5tinIz3/xMxt4x0BcCvjtM0o6MS
9HqBswc5s/mVogYJs/TUXc8U0AQs7R3wqc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/B 
7ADjKjZKQwCbWR9nUt9kpBzGLtSJl22eM4dee/pzlAY=                     
-----END CERTIFICATE-----                                        
Serial Number: 0B:D4:7D:8A:03:3C:64:07:17:5A:42:B8:2D:96:7D:E8   
Common Name: api.company.com                                 
Country: IT                                                      
Locality: xxx
Org Unit:Company S.p.A.                        
Issuer CN: GeoTrust RSA CA 2018                     
Issuer Country: US                                  
Issuer Org: DigiCert Inc                            
Issuer Org Unit: www.digicert.com                   
Version: 3                                          
not before: 20220901020000                          
Unknown Field: 02:00:00 01-09-2022                  
not after: 20231003015959                           
Unknown Field: 01:59:59 03-10-2023                  
pub key alg: 1.2.840.113549.1.1.1                   
signature algorithm: 1.2.840.113549.1.1.11
Unknown Field: 0382020F003082020A0282020100CCC0BD9ABB079C2F2116824FB2D19DFA6386DCF092AB6E44BC3043951FA9D643BBB603FF80C9701984548F65A97CA7CE48049E8887D81E69482C9E17018CEA86221E93F570CB1229E2016693FEC007E0670A804391B4471A0B7A9C6AC51C9D4172FA0761D1F9DF6B431D814424424FA0903CA8B8B65138B34353649B3F63C4E22FAF17D243784819D8B44C68471AA8DAF377D438438206E9662F5061B4C42C5C0D3628D713EDD59C555FDAC16386E4D4EF745F31DD759AFDBBD175DD4E443D4912E8493C6BE3C39B629C8CF7FF1331B78C7405C0AF8ED334A3A312F47A81B30739B3F995A20609B3F4D45DCF14D0042CED1DF0A9C8C7C4053B4B37E62ABEB75BEB973B799900A00F5406EB6BC201134661359C92FC9DC12AC7645E6F5F0481B3D9594C5E6676C531E07BB9DBE170004016051B0C388B7A04A7A338439BEF160D0ABD749B38C1FB4F77573E35E03D54E5D56D7FF91942C5BFF7FBDB36E663BB37DCC04C6E86AEAB78582C3619BBF62D3629FF6228EE026410532CA390CCB6C55C8DEB48123F296396B45607807A15F4DACFD63F40BB422A1C1CA68BA6AAE68A35A4D155D7521E9BFBFC0E7D305C3F604963025968A76885CA60FF02AB4F26C5D8F0F1E6531AB6D1C0B1C7D92A375959F4129B244C3A0505C88BC3AA3F30F7003BA92222FF4C6668F8E608A5E017E57E895FC4117E2D034476FD88ED62865A59950203010001
Unknown Field: 4096
Unknown Field: C4462CCB6C9327EBEB9816A7E0456706                                  
Unknown Field: 1.2.840.113549.2.5                                                
Unknown Field: 1EA4315CFB7863E692CFE31F61763839C826949D                          
Unknown Field: E6DCB12F56C9F000776303467C12F5AC7F3232AD75925966DEC76C1EABBC7C30  
Unknown Field: 5                                      
Unknown Field: api.bonfiglioli.com                    
Unknown Field: 0                                      
Unknown Field: 1.3.6.1.5.5.7.3.2                      
Unknown Field: 1.3.6.1.5.5.7.3.1                      
Unknown Field: 2.23.140.1.2.2                         
Unknown Field: http://status.geotrust.com             
                                                      
Protocol Used: TLS Version 1.2                        
http_persist_req(POST) entered.                       
http_long_ParseURL(): entered                         
http_long_ParseURL(): entered                         
do_oper(POST): entered                                
There are 0 cookies in the cache                      
POST /gateway/ch-dw2000/v1/files/sample HTTP/1.1      
Host: api-qty.company.com                         
User-Agent: http-api/1.45                             
Content-Type: text/plain     
Content-Length: 102                                                                                                        
Authorization: Bearer eyJraWQiOiI1OGE3NzBkMC03MWFlLTExZWQtOWUwYS1iZGMzMzY3MDA4NGQiLCJhbGciOiJSUzI1NiJ9.eyJjbGl.....
X-COMPANY-TRANSACTIONID: EsempioCSVdaDW2000.csv    


senddoc(): entered
Field1|Field2|Field3
Riga1_F1|Riga1_F2|Riga1_F3
Riga2_F1|Riga2_F2|Riga2_F3
Riga3_F1|Riga3_F2|Riga3_F3

recvresp(): entered
HTTP/1.1 400 Bad Request
Date: Mon, 05 Jun 2023 07:47:01 GMT
Content-Type: text/html
Content-Length: 150
Connection: close
Server: APIGW
                                         
                                         
SetError() £13: HTTP/1.1 400 Bad Request 
recvresp(): end with 400                 
recvdoc parms: identity 150              
header_load_cookies() entered            
recvdoc(): entered                       
SetError() £0:                           
recvdoc(): Receiving 150 bytes.          
<html>                                   
<head><title>400 Bad Request</title></head>  
<body>                                       
<center><h1>400 Bad Request</h1></center>    
<hr><center>nginx</center>                   
</body>                                      
</html>                                      
                                             
SetError() £13: HTTP/1.1 400 Bad Request     
http_close(): entered                                                                                                                     
                                                
It is usual to obtain SetError() £13 with simbol £ ?
May be there is some problem about ccsid?
Thank you in advance
Monica

Re: 400 Bad Request

Posted: Mon Jun 05, 2023 9:54 pm
by emaxt6
I guess you are on an "italian" machine... you should see # actually

# in "american" has the same hex value as £ in "italian" (CCSID 37 and CCSID 280 usually involved).
So yes, maybe it is the stream file you are logging (or the viewer) to without correct ccsid.
try to leave the default (a file in /tmp is created).

Anyway the final behaviour doesn't change.

Regarding your service: if you have access to the people running the service ask for exact encoding detail and what they see.

Otherwise, if you have a successful curl, try to run curl with all the trace and verbose options on, to see what it is really exchanged via curl.

Re: 400 Bad Request

Posted: Tue Jun 06, 2023 12:23 pm
by moni_66
Hi Scott,
now the program run fine, I removed http_setOption('content-type':'text/plain'); and declared it only http_req.
In other similar program, I simply replaced http_post with http_req and now it run fine.
Thanky you very much for your precious support.
Monica