1 Attachment(s)
HttpPostRequest Parameters
Hello guys, i'm trying to consume a service that needs some parameters(3 strings and a XML file), but i'm failing to pass the parameters by http request, what i know is that ws is not a soap(there is not a wsdl) and is not a rest ws, a normal http ws i guess?
I was successful with postman doing this way:
[ATTACH=CONFIG]12513[/ATTACH]
with vdf i'm at this point now:
[CODE]
Object oWebButtonNFSe is a cWebButton
Set piColumnSpan to 0
Set psCaption to "NFS-E"
Object oHttpNFSe is a cHttpTransfer
Set psRemoteHost to 'demonstracao.nfs-e.net'
Set pbShowErrorDialog to True
Property String psAllData
Procedure OnDataReceived String sContentType String sData
String sAll
Get psAllData to sAll
Set psAllData to (sAll + sData)
End_Procedure
End_Object
Procedure OnClick
Handle hoHttp hoXml hoSentXml hoRcvdXml
String sSentXml sRcvdXml
Boolean bOk
Integer iCode
Get AddHeader of oHttpNFSe "Content-type" "multipart/form-data" to bOk
Get HttpPostRequest of oHttpNFSe "datacenter/include/nfw/importa_nfw/nfw_import_upload.php?eletron=1" "C:\GroupErp_trunk\teste.xml" True to sRcvdXml
Get ResponseStatusCode of oHttpNFSe to iCode
Get psAllData of oHttpNFSe to sRcvdXml
End_Procedure
End_Object
[/CODE]
I connect and I get a return with a custom error because i'm failing to pass the right parameters (3 strings and a xml), how can i do my post request with parameters like i do in postman?
thanks.
Re: HttpPostRequest Parameters
Salvadori
Can you post what Postman has under the Body --> raw tab. That should give us a better idea of what you need to build into your HTTP request.
Mike
1 Attachment(s)
Re: HttpPostRequest Parameters
[QUOTE=Mike Peat;340765]Salvadori
Can you post what Postman has under the Body --> raw tab. That should give us a better idea of what you need to build into your HTTP request.
Mike[/QUOTE]
thanks @Mike, this raw tab only shows me the response, there is a code explorer that shows me how postman build the HTTP request i hope this help you to help me ( :O ), it seems headers parameters but i'm failing to build this on VDF
[ATTACH=CONFIG]12516[/ATTACH]
Re: HttpPostRequest Parameters
You only appear to be passing your XML file and not the username and password that are part of the form data required
Seems a bit odd it does not use Basic Authentication but postman seems to suggest not
This may help
[url]https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST[/url]
Re: HttpPostRequest Parameters
Salvadori
In your initial screen-shot you are showing in Postman the Body --> [B]form-data[/B]. Two radio-buttons to the of right "form-data" (on the line below "Body" is "[B]raw[/B]".
Whatever is in there is what you will need to build into your HTTP POST in DataFlex to get the same result.
Mike
1 Attachment(s)
Re: HttpPostRequest Parameters
[QUOTE=Mike Peat;340771]Salvadori
In your initial screen-shot you are showing in Postman the Body --> [B]form-data[/B]. Two radio-buttons to the of right "form-data" (on the line below "Body" is "[B]raw[/B]".
Whatever is in there is what you will need to build into your HTTP POST in DataFlex to get the same result.
Mike[/QUOTE]
ok, i understand you, there is nothing on raw tab, because when i tried to use Postman, i chose for the form-data type to pass my parameters, what worked, when I choose for the raw type, postman wait me to write some code, but i do not know exactly what to write here.
[ATTACH=CONFIG]12517[/ATTACH]
Re: HttpPostRequest Parameters
[QUOTE=Focus;340770]You only appear to be passing your XML file and not the username and password that are part of the form data required
Seems a bit odd it does not use Basic Authentication but postman seems to suggest not
This may help
[URL]https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST[/URL][/QUOTE]
thanks for the link @Focus i'll read it carefully, i feel like i'm close but not close enough ;/
Re: HttpPostRequest Parameters
Salvadori - my bad: you are correct. I was hoping that "raw" tab would show you what it was going to send. Alas not.
Re: HttpPostRequest Parameters
Salvadori
OK, next suggestion. Can you use an intercept tool such as Burp ([URL]https://portswigger.net/burp/communitydownload[/URL])? If you set that up and then configure Postman (File --> Settings --> Proxy) to use it as a proxy server, you should be able to see what Postman is actually sending and use that to build your HTTP POST request in DataFlex.
I just did something similar (two parameters plus a file - just a .sws file I had handy) and here is what I got in Burp:
[code]
Content-Type: multipart/form-data; boundary=--------------------------250669598508499980094384
... // more headers and many, many cookies we are not interested in
----------------------------250669598508499980094384
Content-Disposition: form-data; name="foo"
bar
----------------------------250669598508499980094384
Content-Disposition: form-data; name="me"
Mike
----------------------------250669598508499980094384
Content-Disposition: form-data; name="f1"; filename="WebOrder.sws"
Content-Type: application/octet-stream
[Properties]
Version=19.1
[WorkspacePaths]
ConfigFile=.\Programs\Config.ws
[Projects]
Project0=WebApp.src
[Conditionals]
Is$WebApp=True
[Libraries]
Lib1=..\DataFlex Reports\DataFlex Reports Demo.sws
----------------------------250669598508499980094384--
[/code]
So, what you need to do is build something like that in your HTTP request.
[code]
Use seq_chnl.pkg
...
String sBoundary sLF sBody
UChar[] ucaFileContent ucaBody
Boolean bOK
Integer iChn
Move (Character(10)) to sLF
// Read in your file content
Get SEQ_New_Channel to iChn
Direct_Input channel iChn ("binary:" + sFilePathAndName)
Read_Block channel iChn ucaFileContent -1
Close_Input
Send SEQ_Release_Channel iChn
// Set the Content-Type header:
Move "--------------------------250669598508499980094384" to sBoundary
Get AddHeader of oHttp "Content-Type" ("multipart/form-data; boundary=" + sBoundary) to bOK
// Note the "boundary" value can be any old rubbish, but you can just use this one if you like <g>
// Next you have to build up the body
Move (sBoundary + sLF) to sBody
Move (sBody + 'Content-Disposition: form-data; name="foo"' + sLF + sLF) to sBody
Move (sBody + "bar" + sLF) to sBody
Move (sBody + sBoundary + sLF) to sBody
Move (sBody + 'Content-Disposition: form-data; name="me"' + sLF + sLF) to sBody
Move (sBody + "Mike" + sLF) to sBody
Move (sBody + sBoundary + sLF) to sBody
Move (sBody + 'Content-Disposition: form-data; name="f1"; filename="WebOrder.sws"' + sLF) to sBody
Move (sBody + 'Content-Type: application/octet-stream' + sLF + sLF) to sBody
// Now move it all into a UChar array:
Move (StringToUCharArray(sBody)) to ucaBody
// Add in your file content
Move (AppendArray(ucaBody, ucaFileContent)) to ucaBody
// Terminate the body at the end of the UChar array:
Move (AppendArray(ucaBody, StringToUCharArray(sLF + sLF + sBoundary + "--" + sLF)) to ucaBody
// Now make your call:
Get HttpVerbAddrRequest of oHttp sPath (AddressOf(ucaBody)) (SizeOfArray(ucaBody)) False "POST" to bOK
[/code]
I have tested this [U]not at all[/U] and it is probably full of bugs and typos, but it might give you an idea of how to proceed.
You might want to write the body UChar array to a file before sending so you can check that it does actually match what you can see in Burp or whatever.
HTH
Mike
Re: HttpPostRequest Parameters
download Fiddler. It will allow you to look at all the data sent from the postman post and analyze what is missing from your VDF program. look at all the http headers as well as the RAW body data and compare the two
most times you can make it work in DF as well but we had a few web services that DF couldnt handle. in that case we created an intermediate C# dll to do the call