POST request to URL

Posted by Admin on 19-Feb-2009 02:30

TechData (Supplier) introduces a service that accepts XML message via POST request. So I can receive XML data with online prices and availibility information. But I don't have any idea how to begin.

I have to post a message to "http://intcom.xml.quality.techdata.de:8080/Onlchk".

Can anyone help me please? Thank you.

All Replies

Posted by Simon de Kraa on 19-Feb-2009 02:57

Maybe this will help?

Edit: Maybe there are other options. Progress version?

Message was edited by:

Simon de Kraa

Posted by Admin on 19-Feb-2009 03:20

progress 10.1B

Thanks for the information, i start testing now

Posted by Admin on 19-Feb-2009 03:52

hallo simon,

When i test the connection a receive the follow error:

connection failure

unknown host http://intcom.xml.techdata-europe.com:8080/Onlchk

My code to test conection:

DEFINE VARIABLE vcHost AS CHARACTER

INITIAL "http://intcom.xml.techdata-europe.com:8080/Onlchk"

NO-UNDO.

DEFINE VARIABLE vcPort AS CHARACTER INITIAL "8080" NO-UNDO.

DEFINE VARIABLE vhSocket AS HANDLE NO-UNDO.

CREATE SOCKET vhSocket.

vhSocket:CONNECT('-H ' + vcHost + ' -S ' + vcPort) NO-ERROR.

IF vhSocket:CONNECTED() = FALSE THEN

DO:

MESSAGE "Connection failure" VIEW-AS ALERT-BOX.

MESSAGE ERROR-STATUS:GET-MESSAGE(1) VIEW-AS ALERT-BOX.

RETURN.

END.

vhSocket:DISCONNECT() NO-ERROR.

Posted by Admin on 19-Feb-2009 04:00

Try intcom.xml.techdata-europe.com as the value for vcHost.

The host is just one part of the URL.

Posted by Admin on 19-Feb-2009 04:31

Thanks for the tip, but i still have the same error

Posted by Admin on 19-Feb-2009 04:45

This works for me... Is port 8080 blocked in your firewall? Do you need a Proxy server?

Posted by Admin on 19-Feb-2009 04:57

perfect, the connection is ok

but how can i reach the onlchk (online check) in

intcom.xml.techdata-europe.com:8080/onlchk

I'm very new to web services and stuff. So I will thank you for the help

Posted by Simon de Kraa on 19-Feb-2009 05:02

This is handled in the PostRequest procedure.

You can do a "view source" (using your webbrowser) on the http page to check out the path and parameters.

Posted by Admin on 19-Feb-2009 05:23

i understand that i have to put /onlchk as parameter in PostRequest.

but first i have top upload an xml en than i receive the online check information.

So i have to run PostRequest first and then 'getResponse'?

How do i have to generate the request with the XML inside?

vcRequest = 'POST ' + "/Onlchk" + ' HTTP/1.0rn' +

'Content-Type: multipart/form-datarn' +

'Content-Length:' + string(LENGTH(postdata)) + 'rn' +

'rn' +

postData + 'rn'

A lot of questions, i know. Thanks again for all the help

Posted by Simon de Kraa on 19-Feb-2009 06:24

Yes, I believe you have to somehow send the XML file with postrequest and then you will get a response that can be processed in getresponse.

Maybe this will help?

Posted by Admin on 19-Feb-2009 06:31

Did you ask the service provider if a SOAP version of the service is available somewhere? That would probably be the more efficient way of using the service.

Posted by Admin on 19-Feb-2009 06:56

I gonna ask

Posted by Admin on 19-Feb-2009 07:04

no, not available sorry

Posted by Admin on 19-Feb-2009 07:23

This link may be helpful: http://developers.sun.com/mobility/midp/ttips/HTTPPost/

The POST request consists of the

POST /Onlchk

Content-Length in bytesand

Content-Type: text/xml

followed by an empty line and then the XML document.

The documentation and samples CD/download from Progress contains a http get sample: src\samples\sockets\HTTP\Sockets-HTTP.p

It is relatively easy to build a POST out of it. Basically you need to look at the socked response handling procedure.

Posted by Admin on 19-Feb-2009 09:16

I can sent the post and i receive a response.

However, it's an error - no boundary found (see attached file)

Do yo now what it means?

Thanks

Kurt

Posted by Simon de Kraa on 19-Feb-2009 09:25

I think you are close but have to set the boundary. See http://www.mail-archive.com/cactus-user@jakarta.apache.org/msg06500.html for an example.

Posted by Admin on 19-Feb-2009 10:00

I setted the boundary but i receive an new error java.util.NoSuchElementException

code:

vcRequest = "POST http://intcom.xml.techdata-europe.com:8080/Onlchk" + " HTTP/1.0" + "rn" +

"Content-Type:multipart/form-data; boundary=" + cBoundary + "rn" + cBoundary +

"Content-Disposition:form-data;name=xmlmsg" +

"rn" + "rn" +

postData + "rn" + cBoundary.

Posted by Simon de Kraa on 19-Feb-2009 10:35

I'm not sure if this could be the problem but when you look at the examples in http://www.ietf.org/rfc/rfc1867.txt you see that there are additional "--" being used and you are not using them.

Content-type: multipart/form-data, boundary=AaB03x

--AaB03x

content-disposition: form-data; name="field1"

Joe Blow

--AaB03x

content-disposition: form-data; name="pics"; filename="file1.txt"

Content-Type: text/plain

... contents of file1.txt ...

AaB03x

Posted by Admin on 20-Feb-2009 01:42

i also tried that but with no success

vcRequest = 'POST http://intcom.xml.techdata-europe.com:8080/Onlchk HTTP/1.0rn' +

'Content-Type:multipart/form-data, boundary=' + cBoundary + 'rn' +

'Content-Length:' + string(LENGTH(postData)) + 'rn' +

'--' + cBoundary + 'rn' +

'Content-Disposition:form-data;name=xmlmsg' +

'rn' + 'rn' +

postData + 'rn'+

'' + cBoundary + ''.

ERROR: BAD REQUEST

Posted by Simon de Kraa on 20-Feb-2009 02:44

Could you maybe post the value of the message here? (vcRequest)

Posted by Admin on 20-Feb-2009 02:45

vcRequest = 'POST http://intcom.xml.techdata-europe.com:8080/Onlchk HTTP/1.0rn' +

'Content-Type:multipart/form-data, boundary=' + cBoundary + 'rn' +

'Content-Length:' + string(LENGTH(postData)) + 'rn' +

'--' + cBoundary + 'rn' +

'Content-Disposition:form-data;name=xmlmsg' +

'rn' + 'rn' +

postData + 'rn'+

'' + cBoundary + ''.

Posted by Admin on 20-Feb-2009 02:48

I attached a picture with the response

Posted by Simon de Kraa on 20-Feb-2009 03:05

Could you post the exact value of vcRequest?

Maybe you are missing some blank lines in the message?

Posted by Admin on 20-Feb-2009 03:11

Attached pic is the request I post

Posted by Admin on 20-Feb-2009 03:13

I received follow sample code from TechData

Dim lcString

Set FS = Wscript.CreateObject("Scripting.FileSystemObject")

If fs.FileExists("C:\eva\vbs\xml.txt") Then

Set ts = fs.OpenTextFile("C:\eva\vbs\xml.txt")

Do While Not ts.AtEndOfStream

lcString = lcString & ts.ReadLine

Loop

ts.Close

End If

lcUrl = "http://intcom.xml.techdata-europe.com:8080/Onlchk"

Set loXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP")

lcBoundary = "7d7c3101d0bd2"

lcString = "" & lcBoundary & vbCrLf & "Content-Disposition : form-data; name=""xmlmsg""" & vbCrLf & vbCrLf & lcString & vbCrLf & "" & lcBoundary & "--"

loXMLHTTP.Open "POST",lcUrl,F

loXMLHTTP.setRequestHeader "Content-Type","multipart/form-data;boundary="+lcBoundary

loXMLHTTP.Send lcString

lstr_return=loXMLHTTP.responseXML.xml

WScript.Echo lstr_return

Posted by Simon de Kraa on 20-Feb-2009 03:18

I already see two diffs:

Content-Disposition : form-data --> extra whitespace

multipart/form-data;boundary --> use of ; instead of ,

The message must be exactly the same.

Posted by Admin on 20-Feb-2009 04:13

that was stupid but ... still the same error

I'm desperate

Posted by Simon de Kraa on 20-Feb-2009 04:19

Not sure, but you may need an additional blank line (crlf) after the Content-Length...

Maybe you can send your message to the website supplier for inspection?

Posted by Admin on 20-Feb-2009 04:29

I already did a couple of times, but i do not receive an answer

Posted by Admin on 20-Feb-2009 04:33

then I recive the error 413: request entity too large

Posted by Simon de Kraa on 20-Feb-2009 04:49

Well, I do believe you need the extra CRLF so maybe there is a problem with the value of content-length and the actual length of the message?

Posted by Admin on 20-Feb-2009 05:42

I cheched the conent length and it seems ok

Posted by Simon de Kraa on 20-Feb-2009 05:58

I'm not sure if the Content-Length matters but make sure you don't set it too low. Maybe add 10% too see if your message doesn't get truncated by the server?

Could you post the (ASCII) version of the exact message that you are sending?

Posted by Admin on 20-Feb-2009 06:39

POST http://intcom.xml.techdata-europe.com:8080/Onlchk HTTP/1.0

Content-Type: multipart/form-data; boundary=7d7c3101d0bd2

Content-Length: 338

--7d7c3101d0bd2

Content-Disposition : form-data; name=xmlmsg

7d7c3101d0bd2

Posted by Simon de Kraa on 20-Feb-2009 06:47

Your XML message alone is longer than your content-length...

(and you definitely need the addtional CRLF after the content-length)

cat xmlmsg

wc xmlmsg

13 16 343 xmlmsg

Posted by Admin on 20-Feb-2009 06:48

I deleted the line with the content-length.

Now, I receive a HTTP/1.1 200 response but also with an error (see attached file)

I think that is a (little) step forwards

Posted by Simon de Kraa on 20-Feb-2009 07:24

But you still have the blank line after the conten-type right?

What happens if you fiddle around with the XML message? Delete the header or shorten the XML message or delete the XML message entirely.

Posted by Admin on 20-Feb-2009 07:51

stays the same

sorry

Posted by Simon de Kraa on 20-Feb-2009 07:58

Cr@p!

I'm running out of ideas Kurt...

Maybe someone else can chip in?

Posted by Admin on 20-Feb-2009 09:16

no problem !!!

But I received a mail from Techdata and now they ay that a SOAP version is available. But because needs for every new session an new authentication code, almost nobody uses this method.

I can try it but I don't know anything about SOAP!!! So, again, Your help is very very welkom

Kurt

Posted by Admin on 23-Feb-2009 02:45

Hello again,

can you please help me out with trying the SOAP version?

I run out of time to implement to online check!

Thank you

Posted by Simon de Kraa on 27-Feb-2009 02:36

I suggest you open a new thread with the specs.

Posted by Admin on 08-Apr-2009 13:06

You are very close. However, the action of the form is /TechDataTouchIn/GatewayServlet so that is where the POST should go (rather than to /Onlcheck).

So for instance something like this should work:

POST http://intcom.xml.techdata-europe.com:8080/TechDataTouchIn/GatewayServlet HTTP/1.0
Content-Type: multipart/form-data; boundary=asdfzxcvqwer

--asdfzxcvqwer
Content-Disposition: form-data; name="file"; filename="xmlmsg.xml"
Content-Type: text/xml




122292
1s16QI2q-F9Jt-n25d-AdOH-IcWc9ZK8d27G
Full



1593371
1


--asdfzxcvqwer--

(I have no idea how this is going to format and I don't see a preview option!)

When I test this, I get an error saying I'm not authorized to use the page. I get the same error if I use my browser so I'm guessing it pretty much works.

This thread is closed