Wininet vs. curl, part 2

Started by stevengraff, July 29, 2014, 07:16:46 AM

Previous topic - Next topic

stevengraff

I notice that curl has a -u switch, for transmitting username and password.

Is this the same functionality as offered by the 4th and 5th parameters of iHostConnect?

iHostConnect (handle, host, service, userid, pswd)


Deana

Yes.

The curl documentation for the -u switch indicates
Quote
-u, --user <user:password>
Specify the user name and password to use for server authentication.

The equivalent function in WinBatch is iHostConnect parameters for user id and password.
Deana F.
Technical Support
Wilson WindowWare Inc.

stevengraff

Also, I'm trying to mimic a curl example that uses the -H switch for inserting header information... is there a way of doing that with Wininet?

Deana

Sorry I missed that in your original request. iHttpOpen contains a headers parameter: additional user defined headers. Multiple headers are separated by an @CRLF, NO @CRLF should appear at the end.

Code (winbatch) Select
myheader=StrCat("user_process: My cool app", @CRLF, "app_version: 12.0")
rslt=iHttpOpen(datahandle, myheader , 0, 0)
Deana F.
Technical Support
Wilson WindowWare Inc.

stevengraff

Here's a case where the Header(s) seem to be announcing that the upcoming data ( -d ) will be in the form of an xml string, rather than the traditional name="value" pattern. How would we approach this using Wininet?

curl -H 'Content-Type: application/xml; charset=UTF-8' \
     -H 'Accept: application/xml' \
     -d '<?xml version="1.0" encoding="UTF-8"?>
<Transaction>
  <ExactID>ExactID</ExactID>
  <Password>Password</Password>
  <Transaction_Type>32</Transaction_Type>
  <Transaction_Tag>901975484</Transaction_Tag>
  <Authorization_Num>ET4653</Authorization_Num>
  <DollarAmount>15.75</DollarAmount>
</Transaction>' \
https://api.globalgatewaye4.firstdata.com/transaction

Deana

Quote from: stevengraff on July 30, 2014, 12:00:12 PM
Here's a case where the Header(s) seem to be announcing that the upcoming data ( -d ) will be in the form of an xml string, rather than the traditional name="value" pattern. How would we approach this using Wininet?

curl -H 'Content-Type: application/xml; charset=UTF-8' \
     -H 'Accept: application/xml' \
     -d '<?xml version="1.0" encoding="UTF-8"?>
<Transaction>
  <ExactID>ExactID</ExactID>
  <Password>Password</Password>
  <Transaction_Type>32</Transaction_Type>
  <Transaction_Tag>901975484</Transaction_Tag>
  <Authorization_Num>ET4653</Authorization_Num>
  <DollarAmount>15.75</DollarAmount>
</Transaction>' \
https://api.globalgatewaye4.firstdata.com/transaction


Not sure what to specify for the name in the name/value pair....Maybe give this a try:
Code (winbatch) Select

AddExtender("WWINT44I.DLL",0,"WWINT64I.DLL")

tophandle=iBegin(0,"","")
connecthandle=iHostConnect(tophandle,"api.globalgatewaye4.firstdata.com",@HTTP, "", "")
datahandle=iHttpInit(connecthandle,"POST","/transaction","",0)
If datahandle==0
   err=iGetLastError()
   Message("Last Error",err)
   iClose(tophandle)
   Exit
EndIf

;The iContentData and iContentFile functions are designed to format data and files into a BinaryBuffer in preparation for a HTTP-POST request. Each call returns a endofcontent marker to be used in the subsequent call to the functions.
;When all data has been loaded into the BinaryBuffer, a final call to iContentData with a NULL name and value pair will write a final multipart separator to the buffer.
data = '<?xml version="1.0" encoding="UTF-8"><Transaction><ExactID>ExactID</ExactID><Password>Password</Password><Transaction_Type>32</Transaction_Type><Transaction_Tag>901975484</Transaction_Tag><Authorization_Num>ET4653</Authorization_Num><DollarAmount>15.75</DollarAmount></Transaction>'
size = StrByteCount( data, -1 )
bb=BinaryAlloc(size)
BinaryEodSet(bb,size)
bbaddr=IntControl(42,bb,0,0,0)
endofcontent=0
endofcontent = iContentData(bbaddr,endofcontent,"",data)
endofcontent = iContentData(bbaddr,endofcontent,"","")
myheader = "Content-Type: application/xml; charset=UTF-8" : @CRLF : "Accept: application/xml"
rslt=iHttpOpen(datahandle, myheader, bbaddr, endofcontent)
exit




Deana F.
Technical Support
Wilson WindowWare Inc.