POST request to service, content type, need a web expert

jenskcjenskc Member Posts: 2
Hi anyone

I need some help here.

I'm trying to send a POST request to a webserver using automation MS XML 5.0, ServerXMLHTTP50.

The specification of the interface is like this:
The protocol is based on SSL encrypted HTTP communication and all actions are perfomed by sending a HTTP POST request to https://secure.quickpay.dk/api.

HTTP POST request for cancel:

POST /api HTTP/1.1
Host: secure.quickpay.dk
User-Agent: Mozilla/4.0
Content-Length: 107
Content-Type: application/x-www-form-urlencoded

Therefore I make my request as follows:
//XmlHttpConn is the 'Microsoft XML, v5.0'.ServerXMLHTTP50 automation object
//L_XMLDoc is a 'Microsoft XML, v5.0'.DOMDocument50 automation object
//DataString is a text variable in which a set of values are simply concatenated without separators, thus not key-value pairs

IF ISCLEAR(XmlHttpConn) THEN
  CREATE(XmlHttpConn);

XmlHttpConn.open('POST','https://secure.quickpay.dk/api',FALSE); //false is synchronous as compared to asynchronous

XmlHttpConn.setRequestHeader('POST','/api HTTP/1.1');
XmlHttpConn.setRequestHeader('Host','secure.quickpay.dk');
XmlHttpConn.setRequestHeader('User-Agent','Mozilla/4.0');
XmlHttpConn.setRequestHeader('Content-Length',FORMAT(STRLEN(A_ReqURL)));

//XmlHttpConn.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
XmlHttpConn.setRequestHeader('Content-Type','text/plain; charset="utf-8"');

XmlHttpConn.send(DataString);

IF ISCLEAR(L_XMLDoc) THEN
  CREATE(L_XMLDoc);


IF XmlHttpConn.status <> 200 THEN
  MESSAGE('Status %1 %2 %3',XmlHttpConn.status,
                                  XmlHttpConn.statusText,
                                  XmlHttpConn.responseXML,
                                  );

So, here is the problem:
The message keep giving me "Error 500" "Internal Server error" "In use"
that is "Status" is "Error 500", "statusText" is "Internal server error" and "responseXML is "In use"

Apart from not being able to interprete the "In use", I strongly believe that this error is due to the server expecting another content type, and thus it "thinks" it is just receiving nonsense, however, I tried several possibilitites as content types i.e.:

('Content-Type','text/plain');
('Content-Type','text/plain; charset="UTF-8"');
('Content-Type','text/plain; charset="iso-8859-1"');
('Content-Type','text/html);
('Content-Type','text/html; charset="UTF-8"');
('Content-Type','text/html; charset="iso-8859-1"');
('Content-Type','text/xml');
('Content-Type','text/xml; charset="UTF-8"');
('Content-Type','text/xml; charset="iso-8859-1"');

but it gives me the same error all the time.

The problem might be something else, like the other headers being wrong even though they are exactly as the api specification dictates?

Can anyone give me any suggestions to how to solve this problem in a systematic way?

Thanks and kind regards

Jens

Answers

  • GRIZZLYGRIZZLY Member Posts: 127
    What is A_ReqURL ?

    In Content Length tag you should post exact length of your http request with it's headers.
    2 cases: 1) check if you could delete this string from your code to let HTTPServer object calculate length by itself.
    2) if the 1st case won't helps you could save your XML request in file and calculate it lenght by yourself like:
    TempFile := ENVIRON('TEMP') + '\bonus_out.xml';
    XMLOutG.save(TempFile);
    F.OPEN(TempFile);
    OutStrm.WRITETEXT('Content-Length: ' + FORMAT(F.LEN));
    
    Hope this helps!
    Sincerely yours, GRIZZLY
    Follow my blog at http://x-dynamics.blogspot.com
Sign In or Register to comment.